<div class="tutorial-bundle" data-metadata-json='{"difficulty": "medium", "groupedProjectAssets": [{"name": "quiz buttons", "assets": ["button-question.png", "button-ans-A.png", "button-ans-B.png", "button-ans-C.png", "button-ans-D.png"]}]}' data-tip-sha1="97659d5a9b3574215163425998935493415e3382"><div class="front-matter" data-complete-code-text="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
    [
        &quot;What year was the Anglo-Irish Treaty signed?&quot;,
        &quot;1921&quot;,
        &quot;1922&quot;,
        &quot;1923&quot;,
        &quot;A&quot;,
    ],
]

n_questions = len(all_questions_info)

clicked = False
answer = None


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        global clicked

        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        score = 0
        question_index = 0

        while question_index &lt; n_questions:

            question_info = all_questions_info[question_index]

            question = question_info[0]
            ans_A = &quot;A: &quot; + question_info[1]
            ans_B = &quot;B: &quot; + question_info[2]
            ans_C = &quot;C: &quot; + question_info[3]

            text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
            self.say(text)

            clicked = False
            while not clicked:
                pass

            correct_answer = question_info[4]
            if answer == correct_answer:
                self.say_for_seconds(&quot;Correct!&quot;, 2)
                score += 1
            else:
                self.say_for_seconds(&quot;Sorry, that's not correct.&quot;, 2)

            question_index += 1

        text = &quot;You got &quot; + str(score) + &quot; out of &quot; + str(n_questions)
        self.say(text)


class AnswerA(pytch.Sprite):
    Costumes = [&quot;button-ans-A.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(-140, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked, answer
        answer = &quot;A&quot;
        clicked = True


class AnswerB(pytch.Sprite):
    Costumes = [&quot;button-ans-B.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(0, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked, answer
        answer = &quot;B&quot;
        clicked = True


class AnswerC(pytch.Sprite):
    Costumes = [&quot;button-ans-C.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(140, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked, answer
        answer = &quot;C&quot;
        clicked = True
" data-initial-code-text="import pytch
"><h1>Multiple choice quiz</h1><p>In this project we're going to make a quiz, where the player has to
choose between three possible answers to each question.</p></div><div class="chapter-content"><h2>Make the narrator</h2><p>Our game will be run by a <em>narrator</em>.  We will first make a <code>Narrator</code>
sprite, with a costume of a question mark.  The graphics file for
this, <code>"button-question.png"</code>, comes with this tutorial.</p><div class="patch-container" data-code-as-of-commit='import pytch


class Narrator(pytch.Sprite):
    Costumes = ["button-question.png"]
' data-slug="add-Narrator-Sprite"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>1</pre></td><td class="linenum"><pre>1</pre></td><td><pre>import pytch</pre></td></tr></tbody><tbody class="diff-add" data-added-text='

class Narrator(pytch.Sprite):
    Costumes = ["button-question.png"]
'><tr><td class="linenum"></td><td class="linenum"><pre>2</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>3</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>4</pre></td><td><pre>class Narrator(pytch.Sprite):</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>5</pre></td><td><pre>    Costumes = ["button-question.png"]</pre></td></tr></tbody></table></div></div><p>If you run the program now, the question-mark button should appear in
the middle of the screen.</p><p>Let's make the narrator announce the quiz when the program starts.  To
do this we'll write some code which runs when the green flag is
clicked:</p><div class="patch-container" data-code-as-of-commit="import pytch


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)
" data-slug="make-Narrator-announce-quiz"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>3</pre></td><td class="linenum"><pre>3</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>4</pre></td><td class="linenum"><pre>4</pre></td><td><pre>class Narrator(pytch.Sprite):</pre></td></tr><tr><td class="linenum"><pre>5</pre></td><td class="linenum"><pre>5</pre></td><td><pre>    Costumes = ["button-question.png"]</pre></td></tr></tbody><tbody class="diff-add" data-added-text="
    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)
"><tr><td class="linenum"></td><td class="linenum"><pre>6</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>7</pre></td><td><pre>    @pytch.when_green_flag_clicked</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>8</pre></td><td><pre>    def play_quiz(self):</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>9</pre></td><td><pre>        self.say_for_seconds("Let's begin!", 3)</pre></td></tr></tbody></table></div></div></div><div class="chapter-content"><h2>How to store the quiz questions?</h2><p>Before we write more code, we need to stop and think about how we're
going to store the information needed to make a quiz.  A quiz is made
up of questions, so we'll start by thinking about a single quiz
question.</p><p>What are the parts of a quiz question?  We need to know:</p><ul>
<li>the actual question;</li>
<li>the three possible answers;</li>
<li>which answer is the correct one.</li>
</ul><p>To record all these things, we're going to use a Python feature called
a <em>list</em>.  This is very like a Scratch list, but more powerful in ways
we'll see later on.</p><p>The five items in the list will be</p><ul>
<li>the question;</li>
<li>answer A;</li>
<li>answer B;</li>
<li>answer C;</li>
<li>a letter saying which answer is correct (<code>"A"</code>, <code>"B"</code>, or <code>"C"</code>).</li>
</ul><p>In Python, the items of a list are written between square brackets
(<code>[]</code>) and have their items separated by commas (<code>,</code>).</p><p>Let's add a question to our program, stored in a variable, to get some
experience working with Python lists:</p><div class="patch-container" data-code-as-of-commit="import pytch


question_info = [
    &quot;What is the capital of Ireland?&quot;,
    &quot;Dublin&quot;,
    &quot;Cork&quot;,
    &quot;Galway&quot;,
    &quot;A&quot;,
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)
" data-slug="add-first-question-info"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>1</pre></td><td class="linenum"><pre>1</pre></td><td><pre>import pytch</pre></td></tr><tr><td class="linenum"><pre>2</pre></td><td class="linenum"><pre>2</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>3</pre></td><td class="linenum"><pre>3</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-add" data-added-text='question_info = [
    "What is the capital of Ireland?",
    "Dublin",
    "Cork",
    "Galway",
    "A",
]


'><tr><td class="linenum"></td><td class="linenum"><pre>4</pre></td><td><pre>question_info = [</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>5</pre></td><td><pre>    "What is the capital of Ireland?",</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>6</pre></td><td><pre>    "Dublin",</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>7</pre></td><td><pre>    "Cork",</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>8</pre></td><td><pre>    "Galway",</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>9</pre></td><td><pre>    "A",</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>10</pre></td><td><pre>]</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>11</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>12</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>4</pre></td><td class="linenum"><pre>13</pre></td><td><pre>class Narrator(pytch.Sprite):</pre></td></tr><tr><td class="linenum"><pre>5</pre></td><td class="linenum"><pre>14</pre></td><td><pre>    Costumes = ["button-question.png"]</pre></td></tr><tr><td class="linenum"><pre>6</pre></td><td class="linenum"><pre>15</pre></td><td><pre></pre></td></tr></tbody></table></div></div><p>You'll see that I've added the code spread across seven lines, to make
it easier for a human to read.  Python lets you split code across
lines in some situations, such as when giving the items in a list like
this.  Python also allows you to have a comma after the last item in a
list, which I've included here.</p><h3>Working with lists in Python: experimental code</h3><p>First we'll explore how to use the different pieces of information in
this list.  We'll write some code which is not going to be in our
final game.  This code will let us try out a few things and learn how
lists work in Python.</p><p>Let's start by printing out the list we've just created, using the
Python built-in function <code>print()</code>:</p><div class="patch-container" data-code-as-of-commit="import pytch


question_info = [
    &quot;What is the capital of Ireland?&quot;,
    &quot;Dublin&quot;,
    &quot;Cork&quot;,
    &quot;Galway&quot;,
    &quot;A&quot;,
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)
        print(question_info)
" data-slug="print-single-question-info"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>16</pre></td><td class="linenum"><pre>16</pre></td><td><pre>    @pytch.when_green_flag_clicked</pre></td></tr><tr><td class="linenum"><pre>17</pre></td><td class="linenum"><pre>17</pre></td><td><pre>    def play_quiz(self):</pre></td></tr><tr><td class="linenum"><pre>18</pre></td><td class="linenum"><pre>18</pre></td><td><pre>        self.say_for_seconds("Let's begin!", 3)</pre></td></tr></tbody><tbody class="diff-add" data-added-text="        print(question_info)
"><tr><td class="linenum"></td><td class="linenum"><pre>19</pre></td><td><pre>        print(question_info)</pre></td></tr></tbody></table></div></div><p>In standard Python, things you <code>print()</code> usually get displayed on the
screen.  In Pytch, <code>print()</code> output appears in the <code>Output</code> tab.  So
to see what the above code has printed, select the <code>Output</code> tab.  Come
back to this <code>Tutorial</code> tab when you're ready to continue.</p><p>Often we want to get a particular item out of a list.  In Scratch, you
would use, for example, this block:</p><pre><code class="language-scratch">(item (3) of [colours v])
</code></pre><p>to get the third item of the <code>colours</code> list.  In Python, we use the
same <code>[]</code>s as are used to write a list.  The other difference between
Scratch and Python is that in Python, the positions are numbered
starting at <em>zero</em>, so the first item in the list is <code>[0]</code>, the second
item is <code>[1]</code>, and so on.</p><p>To see this working, we'll print the first item from our question-info
list, by changing the <code>print()</code> line:</p><div class="patch-container" data-code-as-of-commit="import pytch


question_info = [
    &quot;What is the capital of Ireland?&quot;,
    &quot;Dublin&quot;,
    &quot;Cork&quot;,
    &quot;Galway&quot;,
    &quot;A&quot;,
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)
        print(question_info[0])
" data-slug="print-item-0"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>16</pre></td><td class="linenum"><pre>16</pre></td><td><pre>    @pytch.when_green_flag_clicked</pre></td></tr><tr><td class="linenum"><pre>17</pre></td><td class="linenum"><pre>17</pre></td><td><pre>    def play_quiz(self):</pre></td></tr><tr><td class="linenum"><pre>18</pre></td><td class="linenum"><pre>18</pre></td><td><pre>        self.say_for_seconds("Let's begin!", 3)</pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>19</pre></td><td class="linenum"></td><td><pre>        print(question_info)</pre></td></tr></tbody><tbody class="diff-add" data-added-text="        print(question_info[0])
"><tr><td class="linenum"></td><td class="linenum"><pre>19</pre></td><td><pre>        print(question_info[0])</pre></td></tr></tbody></table></div></div><p>Change the code again to print out the second item:</p><div class="patch-container" data-code-as-of-commit="import pytch


question_info = [
    &quot;What is the capital of Ireland?&quot;,
    &quot;Dublin&quot;,
    &quot;Cork&quot;,
    &quot;Galway&quot;,
    &quot;A&quot;,
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)
        print(question_info[1])
" data-slug="print-item-1"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>16</pre></td><td class="linenum"><pre>16</pre></td><td><pre>    @pytch.when_green_flag_clicked</pre></td></tr><tr><td class="linenum"><pre>17</pre></td><td class="linenum"><pre>17</pre></td><td><pre>    def play_quiz(self):</pre></td></tr><tr><td class="linenum"><pre>18</pre></td><td class="linenum"><pre>18</pre></td><td><pre>        self.say_for_seconds("Let's begin!", 3)</pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>19</pre></td><td class="linenum"></td><td><pre>        print(question_info[0])</pre></td></tr></tbody><tbody class="diff-add" data-added-text="        print(question_info[1])
"><tr><td class="linenum"></td><td class="linenum"><pre>19</pre></td><td><pre>        print(question_info[1])</pre></td></tr></tbody></table></div></div><p>And the fifth:</p><div class="patch-container" data-code-as-of-commit="import pytch


question_info = [
    &quot;What is the capital of Ireland?&quot;,
    &quot;Dublin&quot;,
    &quot;Cork&quot;,
    &quot;Galway&quot;,
    &quot;A&quot;,
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)
        print(question_info[4])
" data-slug="print-item-4"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>16</pre></td><td class="linenum"><pre>16</pre></td><td><pre>    @pytch.when_green_flag_clicked</pre></td></tr><tr><td class="linenum"><pre>17</pre></td><td class="linenum"><pre>17</pre></td><td><pre>    def play_quiz(self):</pre></td></tr><tr><td class="linenum"><pre>18</pre></td><td class="linenum"><pre>18</pre></td><td><pre>        self.say_for_seconds("Let's begin!", 3)</pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>19</pre></td><td class="linenum"></td><td><pre>        print(question_info[1])</pre></td></tr></tbody><tbody class="diff-add" data-added-text="        print(question_info[4])
"><tr><td class="linenum"></td><td class="linenum"><pre>19</pre></td><td><pre>        print(question_info[4])</pre></td></tr></tbody></table></div></div><p>Just to see what happens, experiment with asking for the item at a
position which doesn't make sense.  For example, our list only has
five items in it, so it doesn't make sense to ask for the item at
position 12:</p><div class="patch-container" data-code-as-of-commit="import pytch


question_info = [
    &quot;What is the capital of Ireland?&quot;,
    &quot;Dublin&quot;,
    &quot;Cork&quot;,
    &quot;Galway&quot;,
    &quot;A&quot;,
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)
        print(question_info[12])
" data-slug="print-item-12"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>16</pre></td><td class="linenum"><pre>16</pre></td><td><pre>    @pytch.when_green_flag_clicked</pre></td></tr><tr><td class="linenum"><pre>17</pre></td><td class="linenum"><pre>17</pre></td><td><pre>    def play_quiz(self):</pre></td></tr><tr><td class="linenum"><pre>18</pre></td><td class="linenum"><pre>18</pre></td><td><pre>        self.say_for_seconds("Let's begin!", 3)</pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>19</pre></td><td class="linenum"></td><td><pre>        print(question_info[4])</pre></td></tr></tbody><tbody class="diff-add" data-added-text="        print(question_info[12])
"><tr><td class="linenum"></td><td class="linenum"><pre>19</pre></td><td><pre>        print(question_info[12])</pre></td></tr></tbody></table></div></div><p>You'll see an <em>error</em> in the <code>Errors</code> tab.  Switch back to this
<code>Tutorial</code> tab when you've checked what the error says.</p><p>We've finished exploring this now, so let's delete the temporary code:</p><div class="patch-container" data-code-as-of-commit="import pytch


question_info = [
    &quot;What is the capital of Ireland?&quot;,
    &quot;Dublin&quot;,
    &quot;Cork&quot;,
    &quot;Galway&quot;,
    &quot;A&quot;,
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)
" data-slug="remove-print-item"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>16</pre></td><td class="linenum"><pre>16</pre></td><td><pre>    @pytch.when_green_flag_clicked</pre></td></tr><tr><td class="linenum"><pre>17</pre></td><td class="linenum"><pre>17</pre></td><td><pre>    def play_quiz(self):</pre></td></tr><tr><td class="linenum"><pre>18</pre></td><td class="linenum"><pre>18</pre></td><td><pre>        self.say_for_seconds("Let's begin!", 3)</pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>19</pre></td><td class="linenum"></td><td><pre>        print(question_info[12])</pre></td></tr></tbody></table></div></div></div><div class="chapter-content"><h2>How to store more than one question?</h2><p>A little bit more thinking now will save us time later.  After the
testing we did using <code>print()</code>, we're happy that we can get at the
different pieces of information which make up a single quiz question.
The next thing to think about is how we're going to store more than
one question.</p><p>We will put the questions into a list.  In Scratch, the items in a
list have to be strings or numbers.  In Python, lists can hold other
lists, which is perfect for us.</p><h3>Make a list of lists</h3><p>We'll make some small changes to the code we've already written, and
make a <em>list of lists</em> to store the information about the whole quiz.
First remove the <code>question_info</code> variable name but keep the opening
square bracket:</p><div class="patch-container" data-code-as-of-commit="import pytch


[
    &quot;What is the capital of Ireland?&quot;,
    &quot;Dublin&quot;,
    &quot;Cork&quot;,
    &quot;Galway&quot;,
    &quot;A&quot;,
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)
" data-slug="remove-question-info-assignment"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>1</pre></td><td class="linenum"><pre>1</pre></td><td><pre>import pytch</pre></td></tr><tr><td class="linenum"><pre>2</pre></td><td class="linenum"><pre>2</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>3</pre></td><td class="linenum"><pre>3</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>4</pre></td><td class="linenum"></td><td><pre>question_info = [</pre></td></tr></tbody><tbody class="diff-add" data-added-text="[
"><tr><td class="linenum"></td><td class="linenum"><pre>4</pre></td><td><pre>[</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>5</pre></td><td class="linenum"><pre>5</pre></td><td><pre>    "What is the capital of Ireland?",</pre></td></tr><tr><td class="linenum"><pre>6</pre></td><td class="linenum"><pre>6</pre></td><td><pre>    "Dublin",</pre></td></tr><tr><td class="linenum"><pre>7</pre></td><td class="linenum"><pre>7</pre></td><td><pre>    "Cork",</pre></td></tr></tbody></table></div></div><p>Then add a line opening a new list <code>all_questions_info</code> and a line
closing that same list:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
[
    &quot;What is the capital of Ireland?&quot;,
    &quot;Dublin&quot;,
    &quot;Cork&quot;,
    &quot;Galway&quot;,
    &quot;A&quot;,
]
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)
" data-slug="create-all-questions-info-list"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>1</pre></td><td class="linenum"><pre>1</pre></td><td><pre>import pytch</pre></td></tr><tr><td class="linenum"><pre>2</pre></td><td class="linenum"><pre>2</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>3</pre></td><td class="linenum"><pre>3</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-add" data-added-text="all_questions_info = [
"><tr><td class="linenum"></td><td class="linenum"><pre>4</pre></td><td><pre>all_questions_info = [</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>4</pre></td><td class="linenum"><pre>5</pre></td><td><pre>[</pre></td></tr><tr><td class="linenum"><pre>5</pre></td><td class="linenum"><pre>6</pre></td><td><pre>    "What is the capital of Ireland?",</pre></td></tr><tr><td class="linenum"><pre>6</pre></td><td class="linenum"><pre>7</pre></td><td><pre>    "Dublin",</pre></td></tr></tbody></table><table><tbody class="diff-unch"><tr><td class="linenum"><pre>8</pre></td><td class="linenum"><pre>9</pre></td><td><pre>    "Galway",</pre></td></tr><tr><td class="linenum"><pre>9</pre></td><td class="linenum"><pre>10</pre></td><td><pre>    "A",</pre></td></tr><tr><td class="linenum"><pre>10</pre></td><td class="linenum"><pre>11</pre></td><td><pre>]</pre></td></tr></tbody><tbody class="diff-add" data-added-text="]
"><tr><td class="linenum"></td><td class="linenum"><pre>12</pre></td><td><pre>]</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>11</pre></td><td class="linenum"><pre>13</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>12</pre></td><td class="linenum"><pre>14</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>13</pre></td><td class="linenum"><pre>15</pre></td><td><pre>class Narrator(pytch.Sprite):</pre></td></tr></tbody></table></div></div><p>Indent the list we already have for storing the first question (this
can be done by highlighting the lines and pressing the <code>TAB</code> key):</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ]
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)
" data-slug="reindent-first-question-info"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>2</pre></td><td class="linenum"><pre>2</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>3</pre></td><td class="linenum"><pre>3</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>4</pre></td><td class="linenum"><pre>4</pre></td><td><pre>all_questions_info = [</pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>5</pre></td><td class="linenum"></td><td><pre>[</pre></td></tr><tr><td class="linenum"><pre>6</pre></td><td class="linenum"></td><td><pre>    "What is the capital of Ireland?",</pre></td></tr><tr><td class="linenum"><pre>7</pre></td><td class="linenum"></td><td><pre>    "Dublin",</pre></td></tr><tr><td class="linenum"><pre>8</pre></td><td class="linenum"></td><td><pre>    "Cork",</pre></td></tr><tr><td class="linenum"><pre>9</pre></td><td class="linenum"></td><td><pre>    "Galway",</pre></td></tr><tr><td class="linenum"><pre>10</pre></td><td class="linenum"></td><td><pre>    "A",</pre></td></tr><tr><td class="linenum"><pre>11</pre></td><td class="linenum"></td><td><pre>]</pre></td></tr></tbody><tbody class="diff-add" data-added-text='    [
        "What is the capital of Ireland?",
        "Dublin",
        "Cork",
        "Galway",
        "A",
    ]
'><tr><td class="linenum"></td><td class="linenum"><pre>5</pre></td><td><pre>    [</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>6</pre></td><td><pre>        "What is the capital of Ireland?",</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>7</pre></td><td><pre>        "Dublin",</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>8</pre></td><td><pre>        "Cork",</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>9</pre></td><td><pre>        "Galway",</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>10</pre></td><td><pre>        "A",</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>11</pre></td><td><pre>    ]</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>12</pre></td><td class="linenum"><pre>12</pre></td><td><pre>]</pre></td></tr><tr><td class="linenum"><pre>13</pre></td><td class="linenum"><pre>13</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>14</pre></td><td class="linenum"><pre>14</pre></td><td><pre></pre></td></tr></tbody></table></div></div><p>We want to be able to add more questions, so add a comma after the
closing bracket of our question's list:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)
" data-slug="add-trailing-comma-first-question-info"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>8</pre></td><td class="linenum"><pre>8</pre></td><td><pre>        "Cork",</pre></td></tr><tr><td class="linenum"><pre>9</pre></td><td class="linenum"><pre>9</pre></td><td><pre>        "Galway",</pre></td></tr><tr><td class="linenum"><pre>10</pre></td><td class="linenum"><pre>10</pre></td><td><pre>        "A",</pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>11</pre></td><td class="linenum"></td><td><pre>    ]</pre></td></tr></tbody><tbody class="diff-add" data-added-text="    ],
"><tr><td class="linenum"></td><td class="linenum"><pre>11</pre></td><td><pre>    ],</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>12</pre></td><td class="linenum"><pre>12</pre></td><td><pre>]</pre></td></tr><tr><td class="linenum"><pre>13</pre></td><td class="linenum"><pre>13</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>14</pre></td><td class="linenum"><pre>14</pre></td><td><pre></pre></td></tr></tbody></table></div></div><p>We're now ready to add more questions when we're ready, but first
we'll get some experience working with this idea of a list of lists.</p><h3>Explore how to get items from the list of lists</h3><p>As before, we will use some temporary <code>print()</code> function calls to
check we know what's going on.</p><p>Let's print the whole list of lists:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)
        print(all_questions_info)
" data-slug="print-all-questions-info"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>18</pre></td><td class="linenum"><pre>18</pre></td><td><pre>    @pytch.when_green_flag_clicked</pre></td></tr><tr><td class="linenum"><pre>19</pre></td><td class="linenum"><pre>19</pre></td><td><pre>    def play_quiz(self):</pre></td></tr><tr><td class="linenum"><pre>20</pre></td><td class="linenum"><pre>20</pre></td><td><pre>        self.say_for_seconds("Let's begin!", 3)</pre></td></tr></tbody><tbody class="diff-add" data-added-text="        print(all_questions_info)
"><tr><td class="linenum"></td><td class="linenum"><pre>21</pre></td><td><pre>        print(all_questions_info)</pre></td></tr></tbody></table></div></div><p>And now, instead, we'll print that list's first item.  This will be
the one-question list we had a minute ago:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)
        print(all_questions_info[0])
" data-slug="print-all-questions-info-item-0"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>18</pre></td><td class="linenum"><pre>18</pre></td><td><pre>    @pytch.when_green_flag_clicked</pre></td></tr><tr><td class="linenum"><pre>19</pre></td><td class="linenum"><pre>19</pre></td><td><pre>    def play_quiz(self):</pre></td></tr><tr><td class="linenum"><pre>20</pre></td><td class="linenum"><pre>20</pre></td><td><pre>        self.say_for_seconds("Let's begin!", 3)</pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>21</pre></td><td class="linenum"></td><td><pre>        print(all_questions_info)</pre></td></tr></tbody><tbody class="diff-add" data-added-text="        print(all_questions_info[0])
"><tr><td class="linenum"></td><td class="linenum"><pre>21</pre></td><td><pre>        print(all_questions_info[0])</pre></td></tr></tbody></table></div></div><p>To get a particular item from <em>that</em> list, we use the <code>[]</code> notation
<em>again</em>:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)
        print(all_questions_info[0][2])
" data-slug="print-all-questions-info-item-0-item-2"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>18</pre></td><td class="linenum"><pre>18</pre></td><td><pre>    @pytch.when_green_flag_clicked</pre></td></tr><tr><td class="linenum"><pre>19</pre></td><td class="linenum"><pre>19</pre></td><td><pre>    def play_quiz(self):</pre></td></tr><tr><td class="linenum"><pre>20</pre></td><td class="linenum"><pre>20</pre></td><td><pre>        self.say_for_seconds("Let's begin!", 3)</pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>21</pre></td><td class="linenum"></td><td><pre>        print(all_questions_info[0])</pre></td></tr></tbody><tbody class="diff-add" data-added-text="        print(all_questions_info[0][2])
"><tr><td class="linenum"></td><td class="linenum"><pre>21</pre></td><td><pre>        print(all_questions_info[0][2])</pre></td></tr></tbody></table></div></div><p>Experiment with changing these numbers and check you understand what
you see printed and what errors you get when the numbers don't make
sense.</p><p>When you're happy, get rid of the temporary code:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)
" data-slug="remove-print"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>18</pre></td><td class="linenum"><pre>18</pre></td><td><pre>    @pytch.when_green_flag_clicked</pre></td></tr><tr><td class="linenum"><pre>19</pre></td><td class="linenum"><pre>19</pre></td><td><pre>    def play_quiz(self):</pre></td></tr><tr><td class="linenum"><pre>20</pre></td><td class="linenum"><pre>20</pre></td><td><pre>        self.say_for_seconds("Let's begin!", 3)</pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>21</pre></td><td class="linenum"></td><td><pre>        print(all_questions_info[0][2])</pre></td></tr></tbody></table></div></div></div><div class="chapter-content"><h2>Ask a question</h2><p>We're now ready to start asking a quiz question!</p><p>We'll start by giving a name to the list of information for the
question we're going to ask the player.  We only have one question at
the moment, so we need the item at position zero in the all-questions
list:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_info = all_questions_info[0]
" data-slug="assign-question-info-temporarily"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>18</pre></td><td class="linenum"><pre>18</pre></td><td><pre>    @pytch.when_green_flag_clicked</pre></td></tr><tr><td class="linenum"><pre>19</pre></td><td class="linenum"><pre>19</pre></td><td><pre>    def play_quiz(self):</pre></td></tr><tr><td class="linenum"><pre>20</pre></td><td class="linenum"><pre>20</pre></td><td><pre>        self.say_for_seconds("Let's begin!", 3)</pre></td></tr></tbody><tbody class="diff-add" data-added-text="
        question_info = all_questions_info[0]
"><tr><td class="linenum"></td><td class="linenum"><pre>21</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>22</pre></td><td><pre>        question_info = all_questions_info[0]</pre></td></tr></tbody></table></div></div><p>Next we will pick out and give names to the individual pieces of
information.  We don't <em>have</em> to do this (we could, for example, just
keep saying <code>question_info[0]</code> whenever we want to use the question
itself), but it makes the program easier to read by a human, which is
important.</p><p>The question itself:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_info = all_questions_info[0]

        question = question_info[0]
" data-slug="assign-actual-question"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>20</pre></td><td class="linenum"><pre>20</pre></td><td><pre>        self.say_for_seconds("Let's begin!", 3)</pre></td></tr><tr><td class="linenum"><pre>21</pre></td><td class="linenum"><pre>21</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>22</pre></td><td class="linenum"><pre>22</pre></td><td><pre>        question_info = all_questions_info[0]</pre></td></tr></tbody><tbody class="diff-add" data-added-text="
        question = question_info[0]
"><tr><td class="linenum"></td><td class="linenum"><pre>23</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>24</pre></td><td><pre>        question = question_info[0]</pre></td></tr></tbody></table></div></div><p>And the three different answers the player will choose from:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_info = all_questions_info[0]

        question = question_info[0]
        ans_A = question_info[1]
        ans_B = question_info[2]
        ans_C = question_info[3]
" data-slug="assign-answer-variables-v1"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>22</pre></td><td class="linenum"><pre>22</pre></td><td><pre>        question_info = all_questions_info[0]</pre></td></tr><tr><td class="linenum"><pre>23</pre></td><td class="linenum"><pre>23</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>24</pre></td><td class="linenum"><pre>24</pre></td><td><pre>        question = question_info[0]</pre></td></tr></tbody><tbody class="diff-add" data-added-text="        ans_A = question_info[1]
        ans_B = question_info[2]
        ans_C = question_info[3]
"><tr><td class="linenum"></td><td class="linenum"><pre>25</pre></td><td><pre>        ans_A = question_info[1]</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>26</pre></td><td><pre>        ans_B = question_info[2]</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>27</pre></td><td><pre>        ans_C = question_info[3]</pre></td></tr></tbody></table></div></div><p>(You might notice that we haven't used <code>question_info[4]</code> yet.  This
is the item which tells us which answer is correct.  We'll use it
later.)</p><p>Now we want to glue these parts together into one string.  In Scratch,
you would do something like</p><pre><code class="language-scratch">(join (question) (join (ans_A) (join (ans_B) (ans_C))))
</code></pre><p>In Python, you can join strings together using the <code>+</code> symbol.  Many
programming languages use <code>+</code> for this, because joining two strings
together is a bit like adding them together.</p><p>We'll make the text by joining together the question and the three
possible answers:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_info = all_questions_info[0]

        question = question_info[0]
        ans_A = question_info[1]
        ans_B = question_info[2]
        ans_C = question_info[3]

        text = question + ans_A + ans_B + ans_C
" data-slug="concatenate-text-parts"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>25</pre></td><td class="linenum"><pre>25</pre></td><td><pre>        ans_A = question_info[1]</pre></td></tr><tr><td class="linenum"><pre>26</pre></td><td class="linenum"><pre>26</pre></td><td><pre>        ans_B = question_info[2]</pre></td></tr><tr><td class="linenum"><pre>27</pre></td><td class="linenum"><pre>27</pre></td><td><pre>        ans_C = question_info[3]</pre></td></tr></tbody><tbody class="diff-add" data-added-text="
        text = question + ans_A + ans_B + ans_C
"><tr><td class="linenum"></td><td class="linenum"><pre>28</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>29</pre></td><td><pre>        text = question + ans_A + ans_B + ans_C</pre></td></tr></tbody></table></div></div><p>And now the narrator can say the final text:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_info = all_questions_info[0]

        question = question_info[0]
        ans_A = question_info[1]
        ans_B = question_info[2]
        ans_C = question_info[3]

        text = question + ans_A + ans_B + ans_C
        self.say(text)
" data-slug="say-concatenated-text"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>27</pre></td><td class="linenum"><pre>27</pre></td><td><pre>        ans_C = question_info[3]</pre></td></tr><tr><td class="linenum"><pre>28</pre></td><td class="linenum"><pre>28</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>29</pre></td><td class="linenum"><pre>29</pre></td><td><pre>        text = question + ans_A + ans_B + ans_C</pre></td></tr></tbody><tbody class="diff-add" data-added-text="        self.say(text)
"><tr><td class="linenum"></td><td class="linenum"><pre>30</pre></td><td><pre>        self.say(text)</pre></td></tr></tbody></table></div></div><p>This is nearly right, but needs improving.  Let's start each answer on
a new line.  In a Python string, the sequence <code>\n</code> gets converted into
a special character which starts a new line, so we want to put some of
those in:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_info = all_questions_info[0]

        question = question_info[0]
        ans_A = question_info[1]
        ans_B = question_info[2]
        ans_C = question_info[3]

        text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
        self.say(text)
" data-slug="interleave-newlines-in-text"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>26</pre></td><td class="linenum"><pre>26</pre></td><td><pre>        ans_B = question_info[2]</pre></td></tr><tr><td class="linenum"><pre>27</pre></td><td class="linenum"><pre>27</pre></td><td><pre>        ans_C = question_info[3]</pre></td></tr><tr><td class="linenum"><pre>28</pre></td><td class="linenum"><pre>28</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>29</pre></td><td class="linenum"></td><td><pre>        text = question + ans_A + ans_B + ans_C</pre></td></tr></tbody><tbody class="diff-add" data-added-text='        text = question + "\n" + ans_A + "\n" + ans_B + "\n" + ans_C
'><tr><td class="linenum"></td><td class="linenum"><pre>29</pre></td><td><pre>        text = question + "\n" + ans_A + "\n" + ans_B + "\n" + ans_C</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>30</pre></td><td class="linenum"><pre>30</pre></td><td><pre>        self.say(text)</pre></td></tr></tbody></table></div></div><p>And let's label the answers so the player knows which one is which.
We'll insert <code>"A: "</code> before the first answer:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_info = all_questions_info[0]

        question = question_info[0]
        ans_A = &quot;A: &quot; + question_info[1]
        ans_B = question_info[2]
        ans_C = question_info[3]

        text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
        self.say(text)
" data-slug="label-answer-A-text"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>22</pre></td><td class="linenum"><pre>22</pre></td><td><pre>        question_info = all_questions_info[0]</pre></td></tr><tr><td class="linenum"><pre>23</pre></td><td class="linenum"><pre>23</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>24</pre></td><td class="linenum"><pre>24</pre></td><td><pre>        question = question_info[0]</pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>25</pre></td><td class="linenum"></td><td><pre>        ans_A = question_info[1]</pre></td></tr></tbody><tbody class="diff-add" data-added-text='        ans_A = "A: " + question_info[1]
'><tr><td class="linenum"></td><td class="linenum"><pre>25</pre></td><td><pre>        ans_A = "A: " + question_info[1]</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>26</pre></td><td class="linenum"><pre>26</pre></td><td><pre>        ans_B = question_info[2]</pre></td></tr><tr><td class="linenum"><pre>27</pre></td><td class="linenum"><pre>27</pre></td><td><pre>        ans_C = question_info[3]</pre></td></tr><tr><td class="linenum"><pre>28</pre></td><td class="linenum"><pre>28</pre></td><td><pre></pre></td></tr></tbody></table></div></div><p>and <code>"B: "</code> before the second:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_info = all_questions_info[0]

        question = question_info[0]
        ans_A = &quot;A: &quot; + question_info[1]
        ans_B = &quot;B: &quot; + question_info[2]
        ans_C = question_info[3]

        text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
        self.say(text)
" data-slug="label-answer-B-text"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>23</pre></td><td class="linenum"><pre>23</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>24</pre></td><td class="linenum"><pre>24</pre></td><td><pre>        question = question_info[0]</pre></td></tr><tr><td class="linenum"><pre>25</pre></td><td class="linenum"><pre>25</pre></td><td><pre>        ans_A = "A: " + question_info[1]</pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>26</pre></td><td class="linenum"></td><td><pre>        ans_B = question_info[2]</pre></td></tr></tbody><tbody class="diff-add" data-added-text='        ans_B = "B: " + question_info[2]
'><tr><td class="linenum"></td><td class="linenum"><pre>26</pre></td><td><pre>        ans_B = "B: " + question_info[2]</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>27</pre></td><td class="linenum"><pre>27</pre></td><td><pre>        ans_C = question_info[3]</pre></td></tr><tr><td class="linenum"><pre>28</pre></td><td class="linenum"><pre>28</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>29</pre></td><td class="linenum"><pre>29</pre></td><td><pre>        text = question + "\n" + ans_A + "\n" + ans_B + "\n" + ans_C</pre></td></tr></tbody></table></div></div><p>and <code>"C: "</code> before the third:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_info = all_questions_info[0]

        question = question_info[0]
        ans_A = &quot;A: &quot; + question_info[1]
        ans_B = &quot;B: &quot; + question_info[2]
        ans_C = &quot;C: &quot; + question_info[3]

        text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
        self.say(text)
" data-slug="label-answer-C-text"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>24</pre></td><td class="linenum"><pre>24</pre></td><td><pre>        question = question_info[0]</pre></td></tr><tr><td class="linenum"><pre>25</pre></td><td class="linenum"><pre>25</pre></td><td><pre>        ans_A = "A: " + question_info[1]</pre></td></tr><tr><td class="linenum"><pre>26</pre></td><td class="linenum"><pre>26</pre></td><td><pre>        ans_B = "B: " + question_info[2]</pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>27</pre></td><td class="linenum"></td><td><pre>        ans_C = question_info[3]</pre></td></tr></tbody><tbody class="diff-add" data-added-text='        ans_C = "C: " + question_info[3]
'><tr><td class="linenum"></td><td class="linenum"><pre>27</pre></td><td><pre>        ans_C = "C: " + question_info[3]</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>28</pre></td><td class="linenum"><pre>28</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>29</pre></td><td class="linenum"><pre>29</pre></td><td><pre>        text = question + "\n" + ans_A + "\n" + ans_B + "\n" + ans_C</pre></td></tr><tr><td class="linenum"><pre>30</pre></td><td class="linenum"><pre>30</pre></td><td><pre>        self.say(text)</pre></td></tr></tbody></table></div></div><p>Now run your program and check that what the narrator says looks much
better.</p></div><div class="chapter-content"><h2>Add another question</h2><p>Let's now test the way we've decided to store more than one question.
We want to add a second item to our <code>all_questions_info</code> list.  Just
before the <code>]</code> which closes that list, insert an inner list with the
pieces of information needed for another question:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_info = all_questions_info[0]

        question = question_info[0]
        ans_A = &quot;A: &quot; + question_info[1]
        ans_B = &quot;B: &quot; + question_info[2]
        ans_C = &quot;C: &quot; + question_info[3]

        text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
        self.say(text)
" data-slug="add-centimetres-in-metre-question"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>9</pre></td><td class="linenum"><pre>9</pre></td><td><pre>        "Galway",</pre></td></tr><tr><td class="linenum"><pre>10</pre></td><td class="linenum"><pre>10</pre></td><td><pre>        "A",</pre></td></tr><tr><td class="linenum"><pre>11</pre></td><td class="linenum"><pre>11</pre></td><td><pre>    ],</pre></td></tr></tbody><tbody class="diff-add" data-added-text='    [
        "How many centimetres are there in one metre?",
        "10",
        "100",
        "1000",
        "B",
    ],
'><tr><td class="linenum"></td><td class="linenum"><pre>12</pre></td><td><pre>    [</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>13</pre></td><td><pre>        "How many centimetres are there in one metre?",</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>14</pre></td><td><pre>        "10",</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>15</pre></td><td><pre>        "100",</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>16</pre></td><td><pre>        "1000",</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>17</pre></td><td><pre>        "B",</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>18</pre></td><td><pre>    ],</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>12</pre></td><td class="linenum"><pre>19</pre></td><td><pre>]</pre></td></tr><tr><td class="linenum"><pre>13</pre></td><td class="linenum"><pre>20</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>14</pre></td><td class="linenum"><pre>21</pre></td><td><pre></pre></td></tr></tbody></table></div></div><p>Check you understand what the five different items in this list are.</p><p>We can test this by changing which item we pull out of
<code>all_questions_info</code>:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_info = all_questions_info[1]

        question = question_info[0]
        ans_A = &quot;A: &quot; + question_info[1]
        ans_B = &quot;B: &quot; + question_info[2]
        ans_C = &quot;C: &quot; + question_info[3]

        text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
        self.say(text)
" data-slug="ask-question-1"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>26</pre></td><td class="linenum"><pre>26</pre></td><td><pre>    def play_quiz(self):</pre></td></tr><tr><td class="linenum"><pre>27</pre></td><td class="linenum"><pre>27</pre></td><td><pre>        self.say_for_seconds("Let's begin!", 3)</pre></td></tr><tr><td class="linenum"><pre>28</pre></td><td class="linenum"><pre>28</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>29</pre></td><td class="linenum"></td><td><pre>        question_info = all_questions_info[0]</pre></td></tr></tbody><tbody class="diff-add" data-added-text="        question_info = all_questions_info[1]
"><tr><td class="linenum"></td><td class="linenum"><pre>29</pre></td><td><pre>        question_info = all_questions_info[1]</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>30</pre></td><td class="linenum"><pre>30</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>31</pre></td><td class="linenum"><pre>31</pre></td><td><pre>        question = question_info[0]</pre></td></tr><tr><td class="linenum"><pre>32</pre></td><td class="linenum"><pre>32</pre></td><td><pre>        ans_A = "A: " + question_info[1]</pre></td></tr></tbody></table></div></div><p>The narrator should now ask the new question instead of the original
one.</p><p>When you're happy that this is working, put the code back so it asks
the first question:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_info = all_questions_info[0]

        question = question_info[0]
        ans_A = &quot;A: &quot; + question_info[1]
        ans_B = &quot;B: &quot; + question_info[2]
        ans_C = &quot;C: &quot; + question_info[3]

        text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
        self.say(text)
" data-slug="ask-question-0-again"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>26</pre></td><td class="linenum"><pre>26</pre></td><td><pre>    def play_quiz(self):</pre></td></tr><tr><td class="linenum"><pre>27</pre></td><td class="linenum"><pre>27</pre></td><td><pre>        self.say_for_seconds("Let's begin!", 3)</pre></td></tr><tr><td class="linenum"><pre>28</pre></td><td class="linenum"><pre>28</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>29</pre></td><td class="linenum"></td><td><pre>        question_info = all_questions_info[1]</pre></td></tr></tbody><tbody class="diff-add" data-added-text="        question_info = all_questions_info[0]
"><tr><td class="linenum"></td><td class="linenum"><pre>29</pre></td><td><pre>        question_info = all_questions_info[0]</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>30</pre></td><td class="linenum"><pre>30</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>31</pre></td><td class="linenum"><pre>31</pre></td><td><pre>        question = question_info[0]</pre></td></tr><tr><td class="linenum"><pre>32</pre></td><td class="linenum"><pre>32</pre></td><td><pre>        ans_A = "A: " + question_info[1]</pre></td></tr></tbody></table></div></div></div><div class="chapter-content"><h2>Ask both questions</h2><p>The next step will be to ask the two questions, one after the other.</p><p>We will need to wait after asking the first question:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_info = all_questions_info[0]

        question = question_info[0]
        ans_A = &quot;A: &quot; + question_info[1]
        ans_B = &quot;B: &quot; + question_info[2]
        ans_C = &quot;C: &quot; + question_info[3]

        text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
        self.say(text)

        pytch.wait_seconds(2)
" data-slug="add-wait-after-question-0"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>35</pre></td><td class="linenum"><pre>35</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>36</pre></td><td class="linenum"><pre>36</pre></td><td><pre>        text = question + "\n" + ans_A + "\n" + ans_B + "\n" + ans_C</pre></td></tr><tr><td class="linenum"><pre>37</pre></td><td class="linenum"><pre>37</pre></td><td><pre>        self.say(text)</pre></td></tr></tbody><tbody class="diff-add" data-added-text="
        pytch.wait_seconds(2)
"><tr><td class="linenum"></td><td class="linenum"><pre>38</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>39</pre></td><td><pre>        pytch.wait_seconds(2)</pre></td></tr></tbody></table></div></div><p>And then we want the narrator to ask the second question.  To make a
start on this, let's just copy and paste the code we already have for
asking the first question:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_info = all_questions_info[0]

        question = question_info[0]
        ans_A = &quot;A: &quot; + question_info[1]
        ans_B = &quot;B: &quot; + question_info[2]
        ans_C = &quot;C: &quot; + question_info[3]

        text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
        self.say(text)

        pytch.wait_seconds(2)

        question_info = all_questions_info[0]

        question = question_info[0]
        ans_A = &quot;A: &quot; + question_info[1]
        ans_B = &quot;B: &quot; + question_info[2]
        ans_C = &quot;C: &quot; + question_info[3]

        text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
        self.say(text)
" data-slug="copy-paste-to-ask-question-0-again"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>37</pre></td><td class="linenum"><pre>37</pre></td><td><pre>        self.say(text)</pre></td></tr><tr><td class="linenum"><pre>38</pre></td><td class="linenum"><pre>38</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>39</pre></td><td class="linenum"><pre>39</pre></td><td><pre>        pytch.wait_seconds(2)</pre></td></tr></tbody><tbody class="diff-add" data-added-text='
        question_info = all_questions_info[0]

        question = question_info[0]
        ans_A = "A: " + question_info[1]
        ans_B = "B: " + question_info[2]
        ans_C = "C: " + question_info[3]

        text = question + "\n" + ans_A + "\n" + ans_B + "\n" + ans_C
        self.say(text)
'><tr><td class="linenum"></td><td class="linenum"><pre>40</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>41</pre></td><td><pre>        question_info = all_questions_info[0]</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>42</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>43</pre></td><td><pre>        question = question_info[0]</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>44</pre></td><td><pre>        ans_A = "A: " + question_info[1]</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>45</pre></td><td><pre>        ans_B = "B: " + question_info[2]</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>46</pre></td><td><pre>        ans_C = "C: " + question_info[3]</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>47</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>48</pre></td><td><pre>        text = question + "\n" + ans_A + "\n" + ans_B + "\n" + ans_C</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>49</pre></td><td><pre>        self.say(text)</pre></td></tr></tbody></table></div></div><p>Try this now.  What you should find is that the game just asks the
first question twice.  This makes sense, because we just copied the
code.</p><p>Can you work out what we need to change in this code, so that the
narrator asks the second question (which is at position <code>1</code> in the
<code>all_questions_info</code> list) instead of the first question (which is at
position <code>0</code>)?</p><p>This is what we need to change:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_info = all_questions_info[0]

        question = question_info[0]
        ans_A = &quot;A: &quot; + question_info[1]
        ans_B = &quot;B: &quot; + question_info[2]
        ans_C = &quot;C: &quot; + question_info[3]

        text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
        self.say(text)

        pytch.wait_seconds(2)

        question_info = all_questions_info[1]

        question = question_info[0]
        ans_A = &quot;A: &quot; + question_info[1]
        ans_B = &quot;B: &quot; + question_info[2]
        ans_C = &quot;C: &quot; + question_info[3]

        text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
        self.say(text)
" data-slug="ask-question-1-after-question-0"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>38</pre></td><td class="linenum"><pre>38</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>39</pre></td><td class="linenum"><pre>39</pre></td><td><pre>        pytch.wait_seconds(2)</pre></td></tr><tr><td class="linenum"><pre>40</pre></td><td class="linenum"><pre>40</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>41</pre></td><td class="linenum"></td><td><pre>        question_info = all_questions_info[0]</pre></td></tr></tbody><tbody class="diff-add" data-added-text="        question_info = all_questions_info[1]
"><tr><td class="linenum"></td><td class="linenum"><pre>41</pre></td><td><pre>        question_info = all_questions_info[1]</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>42</pre></td><td class="linenum"><pre>42</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>43</pre></td><td class="linenum"><pre>43</pre></td><td><pre>        question = question_info[0]</pre></td></tr><tr><td class="linenum"><pre>44</pre></td><td class="linenum"><pre>44</pre></td><td><pre>        ans_A = "A: " + question_info[1]</pre></td></tr></tbody></table></div></div><p>Your game should now ask both questions, one after the other.</p></div><div class="chapter-content"><h2>Use a loop to ask both questions</h2><p>Working like this is going to get annoying when we have more
questions.  We're going to use the idea of a <em>loop</em> to fix the code
and make it work with any number of questions.</p><p>Look at the difference between the copies of the code.  The only
difference is that we ask for the item at a different position in the
<code>all_questions_info</code> list.</p><p>To see how this can be tidied up, we'll make a variable to hold the
position of the current question.  The word <em>index</em> is often used to
mean what position in a list we're talking about, so we'll call this
variable <code>question_index</code>.  To ask the first question, we need
<code>question_index</code> to be zero:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_index = 0

        question_info = all_questions_info[0]

        question = question_info[0]
        ans_A = &quot;A: &quot; + question_info[1]
        ans_B = &quot;B: &quot; + question_info[2]
        ans_C = &quot;C: &quot; + question_info[3]

        text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
        self.say(text)

        pytch.wait_seconds(2)

        question_info = all_questions_info[1]

        question = question_info[0]
        ans_A = &quot;A: &quot; + question_info[1]
        ans_B = &quot;B: &quot; + question_info[2]
        ans_C = &quot;C: &quot; + question_info[3]

        text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
        self.say(text)
" data-slug="add-question-index-variable"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>26</pre></td><td class="linenum"><pre>26</pre></td><td><pre>    def play_quiz(self):</pre></td></tr><tr><td class="linenum"><pre>27</pre></td><td class="linenum"><pre>27</pre></td><td><pre>        self.say_for_seconds("Let's begin!", 3)</pre></td></tr><tr><td class="linenum"><pre>28</pre></td><td class="linenum"><pre>28</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-add" data-added-text="        question_index = 0

"><tr><td class="linenum"></td><td class="linenum"><pre>29</pre></td><td><pre>        question_index = 0</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>30</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>29</pre></td><td class="linenum"><pre>31</pre></td><td><pre>        question_info = all_questions_info[0]</pre></td></tr><tr><td class="linenum"><pre>30</pre></td><td class="linenum"><pre>32</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>31</pre></td><td class="linenum"><pre>33</pre></td><td><pre>        question = question_info[0]</pre></td></tr></tbody></table></div></div><p>And we want to use this variable in the code:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_index = 0

        question_info = all_questions_info[question_index]

        question = question_info[0]
        ans_A = &quot;A: &quot; + question_info[1]
        ans_B = &quot;B: &quot; + question_info[2]
        ans_C = &quot;C: &quot; + question_info[3]

        text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
        self.say(text)

        pytch.wait_seconds(2)

        question_info = all_questions_info[1]

        question = question_info[0]
        ans_A = &quot;A: &quot; + question_info[1]
        ans_B = &quot;B: &quot; + question_info[2]
        ans_C = &quot;C: &quot; + question_info[3]

        text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
        self.say(text)
" data-slug="use-question-index-when-0"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>28</pre></td><td class="linenum"><pre>28</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>29</pre></td><td class="linenum"><pre>29</pre></td><td><pre>        question_index = 0</pre></td></tr><tr><td class="linenum"><pre>30</pre></td><td class="linenum"><pre>30</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>31</pre></td><td class="linenum"></td><td><pre>        question_info = all_questions_info[0]</pre></td></tr></tbody><tbody class="diff-add" data-added-text="        question_info = all_questions_info[question_index]
"><tr><td class="linenum"></td><td class="linenum"><pre>31</pre></td><td><pre>        question_info = all_questions_info[question_index]</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>32</pre></td><td class="linenum"><pre>32</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>33</pre></td><td class="linenum"><pre>33</pre></td><td><pre>        question = question_info[0]</pre></td></tr><tr><td class="linenum"><pre>34</pre></td><td class="linenum"><pre>34</pre></td><td><pre>        ans_A = "A: " + question_info[1]</pre></td></tr></tbody></table></div></div><p>For the second question, our index variable needs to be <code>1</code>:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_index = 0

        question_info = all_questions_info[question_index]

        question = question_info[0]
        ans_A = &quot;A: &quot; + question_info[1]
        ans_B = &quot;B: &quot; + question_info[2]
        ans_C = &quot;C: &quot; + question_info[3]

        text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
        self.say(text)

        pytch.wait_seconds(2)

        question_index = 1

        question_info = all_questions_info[1]

        question = question_info[0]
        ans_A = &quot;A: &quot; + question_info[1]
        ans_B = &quot;B: &quot; + question_info[2]
        ans_C = &quot;C: &quot; + question_info[3]

        text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
        self.say(text)
" data-slug="update-question-index-to-1"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>40</pre></td><td class="linenum"><pre>40</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>41</pre></td><td class="linenum"><pre>41</pre></td><td><pre>        pytch.wait_seconds(2)</pre></td></tr><tr><td class="linenum"><pre>42</pre></td><td class="linenum"><pre>42</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-add" data-added-text="        question_index = 1

"><tr><td class="linenum"></td><td class="linenum"><pre>43</pre></td><td><pre>        question_index = 1</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>44</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>43</pre></td><td class="linenum"><pre>45</pre></td><td><pre>        question_info = all_questions_info[1]</pre></td></tr><tr><td class="linenum"><pre>44</pre></td><td class="linenum"><pre>46</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>45</pre></td><td class="linenum"><pre>47</pre></td><td><pre>        question = question_info[0]</pre></td></tr></tbody></table></div></div><p>And we need to use it:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
]


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_index = 0

        question_info = all_questions_info[question_index]

        question = question_info[0]
        ans_A = &quot;A: &quot; + question_info[1]
        ans_B = &quot;B: &quot; + question_info[2]
        ans_C = &quot;C: &quot; + question_info[3]

        text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
        self.say(text)

        pytch.wait_seconds(2)

        question_index = 1

        question_info = all_questions_info[question_index]

        question = question_info[0]
        ans_A = &quot;A: &quot; + question_info[1]
        ans_B = &quot;B: &quot; + question_info[2]
        ans_C = &quot;C: &quot; + question_info[3]

        text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
        self.say(text)
" data-slug="use-question-index-when-1"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>42</pre></td><td class="linenum"><pre>42</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>43</pre></td><td class="linenum"><pre>43</pre></td><td><pre>        question_index = 1</pre></td></tr><tr><td class="linenum"><pre>44</pre></td><td class="linenum"><pre>44</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>45</pre></td><td class="linenum"></td><td><pre>        question_info = all_questions_info[1]</pre></td></tr></tbody><tbody class="diff-add" data-added-text="        question_info = all_questions_info[question_index]
"><tr><td class="linenum"></td><td class="linenum"><pre>45</pre></td><td><pre>        question_info = all_questions_info[question_index]</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>46</pre></td><td class="linenum"><pre>46</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>47</pre></td><td class="linenum"><pre>47</pre></td><td><pre>        question = question_info[0]</pre></td></tr><tr><td class="linenum"><pre>48</pre></td><td class="linenum"><pre>48</pre></td><td><pre>        ans_A = "A: " + question_info[1]</pre></td></tr></tbody></table></div></div><p>Test that your program still works.  It should ask the two questions
one after the other.</p><h3>Loop over the questions</h3><p>In Scratch, you could find out how many items there are in a list
called <code>all_questions_info</code> by using this block:</p><pre><code class="language-scratch">(length of [all_questions_info v])
</code></pre><p>In Python we can do something very similar — there's a built-in
<code>len()</code> function.  We'll use this to compute the value of a variable
telling us how many questions there are.  We'll do this at the top of
the program, just after the list of questions:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
]

n_questions = len(all_questions_info)


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_index = 0

        question_info = all_questions_info[question_index]

        question = question_info[0]
        ans_A = &quot;A: &quot; + question_info[1]
        ans_B = &quot;B: &quot; + question_info[2]
        ans_C = &quot;C: &quot; + question_info[3]

        text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
        self.say(text)

        pytch.wait_seconds(2)

        question_index = 1

        question_info = all_questions_info[question_index]

        question = question_info[0]
        ans_A = &quot;A: &quot; + question_info[1]
        ans_B = &quot;B: &quot; + question_info[2]
        ans_C = &quot;C: &quot; + question_info[3]

        text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
        self.say(text)
" data-slug="define-n-questions"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>18</pre></td><td class="linenum"><pre>18</pre></td><td><pre>    ],</pre></td></tr><tr><td class="linenum"><pre>19</pre></td><td class="linenum"><pre>19</pre></td><td><pre>]</pre></td></tr><tr><td class="linenum"><pre>20</pre></td><td class="linenum"><pre>20</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-add" data-added-text="n_questions = len(all_questions_info)

"><tr><td class="linenum"></td><td class="linenum"><pre>21</pre></td><td><pre>n_questions = len(all_questions_info)</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>22</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>21</pre></td><td class="linenum"><pre>23</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>22</pre></td><td class="linenum"><pre>24</pre></td><td><pre>class Narrator(pytch.Sprite):</pre></td></tr><tr><td class="linenum"><pre>23</pre></td><td class="linenum"><pre>25</pre></td><td><pre>    Costumes = ["button-question.png"]</pre></td></tr></tbody></table></div></div><p>Now we can put the actual loop in.  This is <em>similar</em> to the Scratch
blocks</p><pre><code class="language-scratch">repeat until &lt;&gt;
</code></pre><p>or</p><pre><code class="language-scratch">repeat ()
</code></pre><p>but not quite the same.</p><p>In Python, we can use a <code>while</code> loop, which keeps going as long as a
test gives a <code>True</code> answer.  We want to keep asking questions as long
as the index makes sense, i.e., is less than the number of questions.</p><p>To see why we need the index to be less than the number of questions,
remember that if there are, say, 5 questions, the index values we want
to go through one at a time are</p><pre><code>0, 1, 2, 3, 4
</code></pre><p>so the test we want is <code>question_index &lt; n_questions</code>.</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
]

n_questions = len(all_questions_info)


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_index = 0

        while question_index &lt; n_questions:

        question_info = all_questions_info[question_index]

        question = question_info[0]
        ans_A = &quot;A: &quot; + question_info[1]
        ans_B = &quot;B: &quot; + question_info[2]
        ans_C = &quot;C: &quot; + question_info[3]

        text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
        self.say(text)

        pytch.wait_seconds(2)

        question_index = 1

        question_info = all_questions_info[question_index]

        question = question_info[0]
        ans_A = &quot;A: &quot; + question_info[1]
        ans_B = &quot;B: &quot; + question_info[2]
        ans_C = &quot;C: &quot; + question_info[3]

        text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
        self.say(text)
" data-slug="add-while-loop-condition-line"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>30</pre></td><td class="linenum"><pre>30</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>31</pre></td><td class="linenum"><pre>31</pre></td><td><pre>        question_index = 0</pre></td></tr><tr><td class="linenum"><pre>32</pre></td><td class="linenum"><pre>32</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-add" data-added-text="        while question_index &lt; n_questions:

"><tr><td class="linenum"></td><td class="linenum"><pre>33</pre></td><td><pre>        while question_index &lt; n_questions:</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>34</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>33</pre></td><td class="linenum"><pre>35</pre></td><td><pre>        question_info = all_questions_info[question_index]</pre></td></tr><tr><td class="linenum"><pre>34</pre></td><td class="linenum"><pre>36</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>35</pre></td><td class="linenum"><pre>37</pre></td><td><pre>        question = question_info[0]</pre></td></tr></tbody></table></div></div><p>And then we need to move the code to ask the question so that it's
"inside" the <code>while</code> loop.  This is the same as how, in Scratch, you
put blocks inside the <code>repeat</code> block.</p><p>The following change looks fiddly, but all that's happening is that
the code moves across to the right by four spaces.  You can do this in
the editor by highlighting the code, and pressing the <code>TAB</code> key.</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
]

n_questions = len(all_questions_info)


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_index = 0

        while question_index &lt; n_questions:

            question_info = all_questions_info[question_index]

            question = question_info[0]
            ans_A = &quot;A: &quot; + question_info[1]
            ans_B = &quot;B: &quot; + question_info[2]
            ans_C = &quot;C: &quot; + question_info[3]

            text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
            self.say(text)

            pytch.wait_seconds(2)

        question_index = 1

        question_info = all_questions_info[question_index]

        question = question_info[0]
        ans_A = &quot;A: &quot; + question_info[1]
        ans_B = &quot;B: &quot; + question_info[2]
        ans_C = &quot;C: &quot; + question_info[3]

        text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
        self.say(text)
" data-slug="indent-what-is-now-while-loop-body"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>32</pre></td><td class="linenum"><pre>32</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>33</pre></td><td class="linenum"><pre>33</pre></td><td><pre>        while question_index &lt; n_questions:</pre></td></tr><tr><td class="linenum"><pre>34</pre></td><td class="linenum"><pre>34</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>35</pre></td><td class="linenum"></td><td><pre>        question_info = all_questions_info[question_index]</pre></td></tr></tbody><tbody class="diff-add" data-added-text="            question_info = all_questions_info[question_index]
"><tr><td class="linenum"></td><td class="linenum"><pre>35</pre></td><td><pre>            question_info = all_questions_info[question_index]</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>36</pre></td><td class="linenum"><pre>36</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>37</pre></td><td class="linenum"></td><td><pre>        question = question_info[0]</pre></td></tr><tr><td class="linenum"><pre>38</pre></td><td class="linenum"></td><td><pre>        ans_A = "A: " + question_info[1]</pre></td></tr><tr><td class="linenum"><pre>39</pre></td><td class="linenum"></td><td><pre>        ans_B = "B: " + question_info[2]</pre></td></tr><tr><td class="linenum"><pre>40</pre></td><td class="linenum"></td><td><pre>        ans_C = "C: " + question_info[3]</pre></td></tr></tbody><tbody class="diff-add" data-added-text='            question = question_info[0]
            ans_A = "A: " + question_info[1]
            ans_B = "B: " + question_info[2]
            ans_C = "C: " + question_info[3]
'><tr><td class="linenum"></td><td class="linenum"><pre>37</pre></td><td><pre>            question = question_info[0]</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>38</pre></td><td><pre>            ans_A = "A: " + question_info[1]</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>39</pre></td><td><pre>            ans_B = "B: " + question_info[2]</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>40</pre></td><td><pre>            ans_C = "C: " + question_info[3]</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>41</pre></td><td class="linenum"><pre>41</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>42</pre></td><td class="linenum"></td><td><pre>        text = question + "\n" + ans_A + "\n" + ans_B + "\n" + ans_C</pre></td></tr><tr><td class="linenum"><pre>43</pre></td><td class="linenum"></td><td><pre>        self.say(text)</pre></td></tr></tbody><tbody class="diff-add" data-added-text='            text = question + "\n" + ans_A + "\n" + ans_B + "\n" + ans_C
            self.say(text)
'><tr><td class="linenum"></td><td class="linenum"><pre>42</pre></td><td><pre>            text = question + "\n" + ans_A + "\n" + ans_B + "\n" + ans_C</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>43</pre></td><td><pre>            self.say(text)</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>44</pre></td><td class="linenum"><pre>44</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>45</pre></td><td class="linenum"></td><td><pre>        pytch.wait_seconds(2)</pre></td></tr></tbody><tbody class="diff-add" data-added-text="            pytch.wait_seconds(2)
"><tr><td class="linenum"></td><td class="linenum"><pre>45</pre></td><td><pre>            pytch.wait_seconds(2)</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>46</pre></td><td class="linenum"><pre>46</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>47</pre></td><td class="linenum"><pre>47</pre></td><td><pre>        question_index = 1</pre></td></tr><tr><td class="linenum"><pre>48</pre></td><td class="linenum"><pre>48</pre></td><td><pre></pre></td></tr></tbody></table></div></div><p>At the end of each time round the loop, we need to move on to next
question by adding one to the index variable:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
]

n_questions = len(all_questions_info)


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_index = 0

        while question_index &lt; n_questions:

            question_info = all_questions_info[question_index]

            question = question_info[0]
            ans_A = &quot;A: &quot; + question_info[1]
            ans_B = &quot;B: &quot; + question_info[2]
            ans_C = &quot;C: &quot; + question_info[3]

            text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
            self.say(text)

            pytch.wait_seconds(2)

            question_index += 1

        question_index = 1

        question_info = all_questions_info[question_index]

        question = question_info[0]
        ans_A = &quot;A: &quot; + question_info[1]
        ans_B = &quot;B: &quot; + question_info[2]
        ans_C = &quot;C: &quot; + question_info[3]

        text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
        self.say(text)
" data-slug="increment-question-index"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>44</pre></td><td class="linenum"><pre>44</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>45</pre></td><td class="linenum"><pre>45</pre></td><td><pre>            pytch.wait_seconds(2)</pre></td></tr><tr><td class="linenum"><pre>46</pre></td><td class="linenum"><pre>46</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-add" data-added-text="            question_index += 1

"><tr><td class="linenum"></td><td class="linenum"><pre>47</pre></td><td><pre>            question_index += 1</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>48</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>47</pre></td><td class="linenum"><pre>49</pre></td><td><pre>        question_index = 1</pre></td></tr><tr><td class="linenum"><pre>48</pre></td><td class="linenum"><pre>50</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>49</pre></td><td class="linenum"><pre>51</pre></td><td><pre>        question_info = all_questions_info[question_index]</pre></td></tr></tbody></table></div></div><p>Finally, we can get rid of the code we copied, since the work is now
being done in our loop:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
]

n_questions = len(all_questions_info)


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_index = 0

        while question_index &lt; n_questions:

            question_info = all_questions_info[question_index]

            question = question_info[0]
            ans_A = &quot;A: &quot; + question_info[1]
            ans_B = &quot;B: &quot; + question_info[2]
            ans_C = &quot;C: &quot; + question_info[3]

            text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
            self.say(text)

            pytch.wait_seconds(2)

            question_index += 1
" data-slug="remove-redundant-code"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>45</pre></td><td class="linenum"><pre>45</pre></td><td><pre>            pytch.wait_seconds(2)</pre></td></tr><tr><td class="linenum"><pre>46</pre></td><td class="linenum"><pre>46</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>47</pre></td><td class="linenum"><pre>47</pre></td><td><pre>            question_index += 1</pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>48</pre></td><td class="linenum"></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>49</pre></td><td class="linenum"></td><td><pre>        question_index = 1</pre></td></tr><tr><td class="linenum"><pre>50</pre></td><td class="linenum"></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>51</pre></td><td class="linenum"></td><td><pre>        question_info = all_questions_info[question_index]</pre></td></tr><tr><td class="linenum"><pre>52</pre></td><td class="linenum"></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>53</pre></td><td class="linenum"></td><td><pre>        question = question_info[0]</pre></td></tr><tr><td class="linenum"><pre>54</pre></td><td class="linenum"></td><td><pre>        ans_A = "A: " + question_info[1]</pre></td></tr><tr><td class="linenum"><pre>55</pre></td><td class="linenum"></td><td><pre>        ans_B = "B: " + question_info[2]</pre></td></tr><tr><td class="linenum"><pre>56</pre></td><td class="linenum"></td><td><pre>        ans_C = "C: " + question_info[3]</pre></td></tr><tr><td class="linenum"><pre>57</pre></td><td class="linenum"></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>58</pre></td><td class="linenum"></td><td><pre>        text = question + "\n" + ans_A + "\n" + ans_B + "\n" + ans_C</pre></td></tr><tr><td class="linenum"><pre>59</pre></td><td class="linenum"></td><td><pre>        self.say(text)</pre></td></tr></tbody></table></div></div><p>Try your program — it should <em>still</em> ask both questions, one after the
other.</p><p>It might seem like we've just done a lot of work for no real benefit,
but we're about to see why writing this loop is so useful.</p><p>(There are other kinds of loops in Python.  We've picked the <code>while</code>
loop for this tutorial.)</p></div><div class="chapter-content"><h2>Add a third question</h2><p>This is now easy!  We have written our program so that, to add more
questions, the only thing we need to change is the <em>data</em>, not the
<em>code</em> itself.  This is a powerful idea in computer programming.</p><p>To add another question, we just add it to our <code>all_questions_info</code>
list near the top of the program:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
    [
        &quot;What year was the Anglo-Irish Treaty signed?&quot;,
        &quot;1921&quot;,
        &quot;1922&quot;,
        &quot;1923&quot;,
        &quot;A&quot;,
    ],
]

n_questions = len(all_questions_info)


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_index = 0

        while question_index &lt; n_questions:

            question_info = all_questions_info[question_index]

            question = question_info[0]
            ans_A = &quot;A: &quot; + question_info[1]
            ans_B = &quot;B: &quot; + question_info[2]
            ans_C = &quot;C: &quot; + question_info[3]

            text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
            self.say(text)

            pytch.wait_seconds(2)

            question_index += 1
" data-slug="add-third-question"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>16</pre></td><td class="linenum"><pre>16</pre></td><td><pre>        "1000",</pre></td></tr><tr><td class="linenum"><pre>17</pre></td><td class="linenum"><pre>17</pre></td><td><pre>        "B",</pre></td></tr><tr><td class="linenum"><pre>18</pre></td><td class="linenum"><pre>18</pre></td><td><pre>    ],</pre></td></tr></tbody><tbody class="diff-add" data-added-text='    [
        "What year was the Anglo-Irish Treaty signed?",
        "1921",
        "1922",
        "1923",
        "A",
    ],
'><tr><td class="linenum"></td><td class="linenum"><pre>19</pre></td><td><pre>    [</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>20</pre></td><td><pre>        "What year was the Anglo-Irish Treaty signed?",</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>21</pre></td><td><pre>        "1921",</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>22</pre></td><td><pre>        "1922",</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>23</pre></td><td><pre>        "1923",</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>24</pre></td><td><pre>        "A",</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>25</pre></td><td><pre>    ],</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>19</pre></td><td class="linenum"><pre>26</pre></td><td><pre>]</pre></td></tr><tr><td class="linenum"><pre>20</pre></td><td class="linenum"><pre>27</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>21</pre></td><td class="linenum"><pre>28</pre></td><td><pre>n_questions = len(all_questions_info)</pre></td></tr></tbody></table></div></div></div><div class="chapter-content"><h2>Add the answer buttons</h2><p>We're making good progress.  The narrator now asks all the questions,
one after another.</p><p>We now need a way for the player to answer the questions.  We'll do
this by adding three buttons.  The player will click on the button for
the answer they think is correct.</p><p>We'll start with a button to press if the player thinks "A" is the
right answer.  This is a new sprite, with a costume that's provided
with this tutorial:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
    [
        &quot;What year was the Anglo-Irish Treaty signed?&quot;,
        &quot;1921&quot;,
        &quot;1922&quot;,
        &quot;1923&quot;,
        &quot;A&quot;,
    ],
]

n_questions = len(all_questions_info)


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_index = 0

        while question_index &lt; n_questions:

            question_info = all_questions_info[question_index]

            question = question_info[0]
            ans_A = &quot;A: &quot; + question_info[1]
            ans_B = &quot;B: &quot; + question_info[2]
            ans_C = &quot;C: &quot; + question_info[3]

            text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
            self.say(text)

            pytch.wait_seconds(2)

            question_index += 1


class AnswerA(pytch.Sprite):
    Costumes = [&quot;button-ans-A.png&quot;]
" data-slug="add-AnswerA-sprite"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>52</pre></td><td class="linenum"><pre>52</pre></td><td><pre>            pytch.wait_seconds(2)</pre></td></tr><tr><td class="linenum"><pre>53</pre></td><td class="linenum"><pre>53</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>54</pre></td><td class="linenum"><pre>54</pre></td><td><pre>            question_index += 1</pre></td></tr></tbody><tbody class="diff-add" data-added-text='

class AnswerA(pytch.Sprite):
    Costumes = ["button-ans-A.png"]
'><tr><td class="linenum"></td><td class="linenum"><pre>55</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>56</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>57</pre></td><td><pre>class AnswerA(pytch.Sprite):</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>58</pre></td><td><pre>    Costumes = ["button-ans-A.png"]</pre></td></tr></tbody></table></div></div><p>If you try this, you'll see that the new sprite starts off right on
top of the narrator, which is no good.  Make the button move to a
sensible place when the program starts:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
    [
        &quot;What year was the Anglo-Irish Treaty signed?&quot;,
        &quot;1921&quot;,
        &quot;1922&quot;,
        &quot;1923&quot;,
        &quot;A&quot;,
    ],
]

n_questions = len(all_questions_info)


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_index = 0

        while question_index &lt; n_questions:

            question_info = all_questions_info[question_index]

            question = question_info[0]
            ans_A = &quot;A: &quot; + question_info[1]
            ans_B = &quot;B: &quot; + question_info[2]
            ans_C = &quot;C: &quot; + question_info[3]

            text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
            self.say(text)

            pytch.wait_seconds(2)

            question_index += 1


class AnswerA(pytch.Sprite):
    Costumes = [&quot;button-ans-A.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(-140, -120)
" data-slug="init-AnswerA-position"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>56</pre></td><td class="linenum"><pre>56</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>57</pre></td><td class="linenum"><pre>57</pre></td><td><pre>class AnswerA(pytch.Sprite):</pre></td></tr><tr><td class="linenum"><pre>58</pre></td><td class="linenum"><pre>58</pre></td><td><pre>    Costumes = ["button-ans-A.png"]</pre></td></tr></tbody><tbody class="diff-add" data-added-text="
    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(-140, -120)
"><tr><td class="linenum"></td><td class="linenum"><pre>59</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>60</pre></td><td><pre>    @pytch.when_green_flag_clicked</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>61</pre></td><td><pre>    def setup(self):</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>62</pre></td><td><pre>        self.go_to_xy(-140, -120)</pre></td></tr></tbody></table></div></div><p>Going a bit more quickly now, we can add a button the player can click
if they think "B" is the right answer.  This is very similar to the
"A" button, but it has a different costume, and different starting
coordinates.</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
    [
        &quot;What year was the Anglo-Irish Treaty signed?&quot;,
        &quot;1921&quot;,
        &quot;1922&quot;,
        &quot;1923&quot;,
        &quot;A&quot;,
    ],
]

n_questions = len(all_questions_info)


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_index = 0

        while question_index &lt; n_questions:

            question_info = all_questions_info[question_index]

            question = question_info[0]
            ans_A = &quot;A: &quot; + question_info[1]
            ans_B = &quot;B: &quot; + question_info[2]
            ans_C = &quot;C: &quot; + question_info[3]

            text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
            self.say(text)

            pytch.wait_seconds(2)

            question_index += 1


class AnswerA(pytch.Sprite):
    Costumes = [&quot;button-ans-A.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(-140, -120)


class AnswerB(pytch.Sprite):
    Costumes = [&quot;button-ans-B.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(0, -120)
" data-slug="add-AnswerB-sprite-and-init-position"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>60</pre></td><td class="linenum"><pre>60</pre></td><td><pre>    @pytch.when_green_flag_clicked</pre></td></tr><tr><td class="linenum"><pre>61</pre></td><td class="linenum"><pre>61</pre></td><td><pre>    def setup(self):</pre></td></tr><tr><td class="linenum"><pre>62</pre></td><td class="linenum"><pre>62</pre></td><td><pre>        self.go_to_xy(-140, -120)</pre></td></tr></tbody><tbody class="diff-add" data-added-text='

class AnswerB(pytch.Sprite):
    Costumes = ["button-ans-B.png"]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(0, -120)
'><tr><td class="linenum"></td><td class="linenum"><pre>63</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>64</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>65</pre></td><td><pre>class AnswerB(pytch.Sprite):</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>66</pre></td><td><pre>    Costumes = ["button-ans-B.png"]</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>67</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>68</pre></td><td><pre>    @pytch.when_green_flag_clicked</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>69</pre></td><td><pre>    def setup(self):</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>70</pre></td><td><pre>        self.go_to_xy(0, -120)</pre></td></tr></tbody></table></div></div><p>And one for "C":</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
    [
        &quot;What year was the Anglo-Irish Treaty signed?&quot;,
        &quot;1921&quot;,
        &quot;1922&quot;,
        &quot;1923&quot;,
        &quot;A&quot;,
    ],
]

n_questions = len(all_questions_info)


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_index = 0

        while question_index &lt; n_questions:

            question_info = all_questions_info[question_index]

            question = question_info[0]
            ans_A = &quot;A: &quot; + question_info[1]
            ans_B = &quot;B: &quot; + question_info[2]
            ans_C = &quot;C: &quot; + question_info[3]

            text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
            self.say(text)

            pytch.wait_seconds(2)

            question_index += 1


class AnswerA(pytch.Sprite):
    Costumes = [&quot;button-ans-A.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(-140, -120)


class AnswerB(pytch.Sprite):
    Costumes = [&quot;button-ans-B.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(0, -120)


class AnswerC(pytch.Sprite):
    Costumes = [&quot;button-ans-C.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(140, -120)
" data-slug="add-AnswerC-sprite-and-init-position"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>68</pre></td><td class="linenum"><pre>68</pre></td><td><pre>    @pytch.when_green_flag_clicked</pre></td></tr><tr><td class="linenum"><pre>69</pre></td><td class="linenum"><pre>69</pre></td><td><pre>    def setup(self):</pre></td></tr><tr><td class="linenum"><pre>70</pre></td><td class="linenum"><pre>70</pre></td><td><pre>        self.go_to_xy(0, -120)</pre></td></tr></tbody><tbody class="diff-add" data-added-text='

class AnswerC(pytch.Sprite):
    Costumes = ["button-ans-C.png"]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(140, -120)
'><tr><td class="linenum"></td><td class="linenum"><pre>71</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>72</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>73</pre></td><td><pre>class AnswerC(pytch.Sprite):</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>74</pre></td><td><pre>    Costumes = ["button-ans-C.png"]</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>75</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>76</pre></td><td><pre>    @pytch.when_green_flag_clicked</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>77</pre></td><td><pre>    def setup(self):</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>78</pre></td><td><pre>        self.go_to_xy(140, -120)</pre></td></tr></tbody></table></div></div><p>You might be thinking that there must be a better way to do this than
copying and pasting and making small changes to the code.  You're
right, but those ways would take us too far astray from this tutorial.</p></div><div class="chapter-content"><h2>Wait for player to click an answer button</h2><p>There are a few ways different Sprites can work together in Pytch.
We're going to use a <em>shared variable</em> which will say whether the
player has clicked a button yet for this question.  It's <em>shared</em>
because more than one sprite will use it.</p><p>The narrator will set the variable to <code>False</code> when asking a question,
and each answer button will set it to <code>True</code> when it's clicked.</p><p>Because the narrator and the three answer sprites all need to work
with this variable, we'll make it <em>global</em> by defining it near the top
of the program, outside any sprite:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
    [
        &quot;What year was the Anglo-Irish Treaty signed?&quot;,
        &quot;1921&quot;,
        &quot;1922&quot;,
        &quot;1923&quot;,
        &quot;A&quot;,
    ],
]

n_questions = len(all_questions_info)

clicked = False


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_index = 0

        while question_index &lt; n_questions:

            question_info = all_questions_info[question_index]

            question = question_info[0]
            ans_A = &quot;A: &quot; + question_info[1]
            ans_B = &quot;B: &quot; + question_info[2]
            ans_C = &quot;C: &quot; + question_info[3]

            text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
            self.say(text)

            pytch.wait_seconds(2)

            question_index += 1


class AnswerA(pytch.Sprite):
    Costumes = [&quot;button-ans-A.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(-140, -120)


class AnswerB(pytch.Sprite):
    Costumes = [&quot;button-ans-B.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(0, -120)


class AnswerC(pytch.Sprite):
    Costumes = [&quot;button-ans-C.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(140, -120)
" data-slug="add-global-clicked-variable"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>27</pre></td><td class="linenum"><pre>27</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>28</pre></td><td class="linenum"><pre>28</pre></td><td><pre>n_questions = len(all_questions_info)</pre></td></tr><tr><td class="linenum"><pre>29</pre></td><td class="linenum"><pre>29</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-add" data-added-text="clicked = False

"><tr><td class="linenum"></td><td class="linenum"><pre>30</pre></td><td><pre>clicked = False</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>31</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>30</pre></td><td class="linenum"><pre>32</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>31</pre></td><td class="linenum"><pre>33</pre></td><td><pre>class Narrator(pytch.Sprite):</pre></td></tr><tr><td class="linenum"><pre>32</pre></td><td class="linenum"><pre>34</pre></td><td><pre>    Costumes = ["button-question.png"]</pre></td></tr></tbody></table></div></div><p>In Python, you have to give a starting value to a variable.  We're
using <code>False</code> here, because when the program starts, a button has not
been clicked.</p><p>The narrator needs to work with this variable, and in Python you need
to say when you're using a global variable:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
    [
        &quot;What year was the Anglo-Irish Treaty signed?&quot;,
        &quot;1921&quot;,
        &quot;1922&quot;,
        &quot;1923&quot;,
        &quot;A&quot;,
    ],
]

n_questions = len(all_questions_info)

clicked = False


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        global clicked

        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_index = 0

        while question_index &lt; n_questions:

            question_info = all_questions_info[question_index]

            question = question_info[0]
            ans_A = &quot;A: &quot; + question_info[1]
            ans_B = &quot;B: &quot; + question_info[2]
            ans_C = &quot;C: &quot; + question_info[3]

            text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
            self.say(text)

            pytch.wait_seconds(2)

            question_index += 1


class AnswerA(pytch.Sprite):
    Costumes = [&quot;button-ans-A.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(-140, -120)


class AnswerB(pytch.Sprite):
    Costumes = [&quot;button-ans-B.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(0, -120)


class AnswerC(pytch.Sprite):
    Costumes = [&quot;button-ans-C.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(140, -120)
" data-slug="declare-global-clicked-in-Narrator-play-quiz"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>35</pre></td><td class="linenum"><pre>35</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>36</pre></td><td class="linenum"><pre>36</pre></td><td><pre>    @pytch.when_green_flag_clicked</pre></td></tr><tr><td class="linenum"><pre>37</pre></td><td class="linenum"><pre>37</pre></td><td><pre>    def play_quiz(self):</pre></td></tr></tbody><tbody class="diff-add" data-added-text="        global clicked

"><tr><td class="linenum"></td><td class="linenum"><pre>38</pre></td><td><pre>        global clicked</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>39</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>38</pre></td><td class="linenum"><pre>40</pre></td><td><pre>        self.say_for_seconds("Let's begin!", 3)</pre></td></tr><tr><td class="linenum"><pre>39</pre></td><td class="linenum"><pre>41</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>40</pre></td><td class="linenum"><pre>42</pre></td><td><pre>        question_index = 0</pre></td></tr></tbody></table></div></div><p>As soon as the narrator has asked the question, it needs to record the fact
that no button has yet been clicked:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
    [
        &quot;What year was the Anglo-Irish Treaty signed?&quot;,
        &quot;1921&quot;,
        &quot;1922&quot;,
        &quot;1923&quot;,
        &quot;A&quot;,
    ],
]

n_questions = len(all_questions_info)

clicked = False


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        global clicked

        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_index = 0

        while question_index &lt; n_questions:

            question_info = all_questions_info[question_index]

            question = question_info[0]
            ans_A = &quot;A: &quot; + question_info[1]
            ans_B = &quot;B: &quot; + question_info[2]
            ans_C = &quot;C: &quot; + question_info[3]

            text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
            self.say(text)

            clicked = False

            pytch.wait_seconds(2)

            question_index += 1


class AnswerA(pytch.Sprite):
    Costumes = [&quot;button-ans-A.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(-140, -120)


class AnswerB(pytch.Sprite):
    Costumes = [&quot;button-ans-B.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(0, -120)


class AnswerC(pytch.Sprite):
    Costumes = [&quot;button-ans-C.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(140, -120)
" data-slug="clear-clicked-before-asking-question"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>53</pre></td><td class="linenum"><pre>53</pre></td><td><pre>            text = question + "\n" + ans_A + "\n" + ans_B + "\n" + ans_C</pre></td></tr><tr><td class="linenum"><pre>54</pre></td><td class="linenum"><pre>54</pre></td><td><pre>            self.say(text)</pre></td></tr><tr><td class="linenum"><pre>55</pre></td><td class="linenum"><pre>55</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-add" data-added-text="            clicked = False

"><tr><td class="linenum"></td><td class="linenum"><pre>56</pre></td><td><pre>            clicked = False</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>57</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>56</pre></td><td class="linenum"><pre>58</pre></td><td><pre>            pytch.wait_seconds(2)</pre></td></tr><tr><td class="linenum"><pre>57</pre></td><td class="linenum"><pre>59</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>58</pre></td><td class="linenum"><pre>60</pre></td><td><pre>            question_index += 1</pre></td></tr></tbody></table></div></div><p>And then the narrator needs to wait until a button has been clicked.
We want to keep doing nothing as long as <code>clicked</code> is <code>False</code>.  We can
write this test in a more natural-sounding way by using the <code>not</code>
operator:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
    [
        &quot;What year was the Anglo-Irish Treaty signed?&quot;,
        &quot;1921&quot;,
        &quot;1922&quot;,
        &quot;1923&quot;,
        &quot;A&quot;,
    ],
]

n_questions = len(all_questions_info)

clicked = False


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        global clicked

        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_index = 0

        while question_index &lt; n_questions:

            question_info = all_questions_info[question_index]

            question = question_info[0]
            ans_A = &quot;A: &quot; + question_info[1]
            ans_B = &quot;B: &quot; + question_info[2]
            ans_C = &quot;C: &quot; + question_info[3]

            text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
            self.say(text)

            clicked = False
            while not clicked:
                pass

            pytch.wait_seconds(2)

            question_index += 1


class AnswerA(pytch.Sprite):
    Costumes = [&quot;button-ans-A.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(-140, -120)


class AnswerB(pytch.Sprite):
    Costumes = [&quot;button-ans-B.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(0, -120)


class AnswerC(pytch.Sprite):
    Costumes = [&quot;button-ans-C.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(140, -120)
" data-slug="busy-wait-Narrator-until-clicked"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>54</pre></td><td class="linenum"><pre>54</pre></td><td><pre>            self.say(text)</pre></td></tr><tr><td class="linenum"><pre>55</pre></td><td class="linenum"><pre>55</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>56</pre></td><td class="linenum"><pre>56</pre></td><td><pre>            clicked = False</pre></td></tr></tbody><tbody class="diff-add" data-added-text="            while not clicked:
                pass
"><tr><td class="linenum"></td><td class="linenum"><pre>57</pre></td><td><pre>            while not clicked:</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>58</pre></td><td><pre>                pass</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>57</pre></td><td class="linenum"><pre>59</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>58</pre></td><td class="linenum"><pre>60</pre></td><td><pre>            pytch.wait_seconds(2)</pre></td></tr><tr><td class="linenum"><pre>59</pre></td><td class="linenum"><pre>61</pre></td><td><pre></pre></td></tr></tbody></table></div></div><p>The <code>pass</code> statement here does nothing.  Unlike Scratch, Python needs
to have <em>some</em> statements inside a <code>while</code> loop, even if you don't
want anything to happen, so the <code>pass</code> statement is what we use.</p><p>We don't need to wait any more:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
    [
        &quot;What year was the Anglo-Irish Treaty signed?&quot;,
        &quot;1921&quot;,
        &quot;1922&quot;,
        &quot;1923&quot;,
        &quot;A&quot;,
    ],
]

n_questions = len(all_questions_info)

clicked = False


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        global clicked

        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_index = 0

        while question_index &lt; n_questions:

            question_info = all_questions_info[question_index]

            question = question_info[0]
            ans_A = &quot;A: &quot; + question_info[1]
            ans_B = &quot;B: &quot; + question_info[2]
            ans_C = &quot;C: &quot; + question_info[3]

            text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
            self.say(text)

            clicked = False
            while not clicked:
                pass

            question_index += 1


class AnswerA(pytch.Sprite):
    Costumes = [&quot;button-ans-A.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(-140, -120)


class AnswerB(pytch.Sprite):
    Costumes = [&quot;button-ans-B.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(0, -120)


class AnswerC(pytch.Sprite):
    Costumes = [&quot;button-ans-C.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(140, -120)
" data-slug="remove-wait-2-seconds"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>57</pre></td><td class="linenum"><pre>57</pre></td><td><pre>            while not clicked:</pre></td></tr><tr><td class="linenum"><pre>58</pre></td><td class="linenum"><pre>58</pre></td><td><pre>                pass</pre></td></tr><tr><td class="linenum"><pre>59</pre></td><td class="linenum"><pre>59</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>60</pre></td><td class="linenum"></td><td><pre>            pytch.wait_seconds(2)</pre></td></tr><tr><td class="linenum"><pre>61</pre></td><td class="linenum"></td><td><pre></pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>62</pre></td><td class="linenum"><pre>60</pre></td><td><pre>            question_index += 1</pre></td></tr><tr><td class="linenum"><pre>63</pre></td><td class="linenum"><pre>61</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>64</pre></td><td class="linenum"><pre>62</pre></td><td><pre></pre></td></tr></tbody></table></div></div><p>We have solved one half of the problem — we've made the narrator wait
until the <code>clicked</code> variable tells us that an answer button has been
clicked.  But nothing is yet setting that variable to <code>True</code>, so the
narrator will wait forever!</p><p>When any answer button is clicked, it needs to set the global
<code>clicked</code> variable to <code>True</code>.</p><p>Moving a bit more quickly now, we need code which says we're using the
global <code>clicked</code> variable, and then sets it to <code>True</code>.  For the first
answer button (<code>AnswerA</code>), the code we need is:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
    [
        &quot;What year was the Anglo-Irish Treaty signed?&quot;,
        &quot;1921&quot;,
        &quot;1922&quot;,
        &quot;1923&quot;,
        &quot;A&quot;,
    ],
]

n_questions = len(all_questions_info)

clicked = False


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        global clicked

        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_index = 0

        while question_index &lt; n_questions:

            question_info = all_questions_info[question_index]

            question = question_info[0]
            ans_A = &quot;A: &quot; + question_info[1]
            ans_B = &quot;B: &quot; + question_info[2]
            ans_C = &quot;C: &quot; + question_info[3]

            text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
            self.say(text)

            clicked = False
            while not clicked:
                pass

            question_index += 1


class AnswerA(pytch.Sprite):
    Costumes = [&quot;button-ans-A.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(-140, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked
        clicked = True


class AnswerB(pytch.Sprite):
    Costumes = [&quot;button-ans-B.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(0, -120)


class AnswerC(pytch.Sprite):
    Costumes = [&quot;button-ans-C.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(140, -120)
" data-slug="add-AnswerA-clicked-handler"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>67</pre></td><td class="linenum"><pre>67</pre></td><td><pre>    def setup(self):</pre></td></tr><tr><td class="linenum"><pre>68</pre></td><td class="linenum"><pre>68</pre></td><td><pre>        self.go_to_xy(-140, -120)</pre></td></tr><tr><td class="linenum"><pre>69</pre></td><td class="linenum"><pre>69</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-add" data-added-text="    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked
        clicked = True

"><tr><td class="linenum"></td><td class="linenum"><pre>70</pre></td><td><pre>    @pytch.when_this_sprite_clicked</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>71</pre></td><td><pre>    def notify_answered(self):</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>72</pre></td><td><pre>        global clicked</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>73</pre></td><td><pre>        clicked = True</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>74</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>70</pre></td><td class="linenum"><pre>75</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>71</pre></td><td class="linenum"><pre>76</pre></td><td><pre>class AnswerB(pytch.Sprite):</pre></td></tr><tr><td class="linenum"><pre>72</pre></td><td class="linenum"><pre>77</pre></td><td><pre>    Costumes = ["button-ans-B.png"]</pre></td></tr></tbody></table></div></div><p>And we need the same for <code>AnswerB</code>:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
    [
        &quot;What year was the Anglo-Irish Treaty signed?&quot;,
        &quot;1921&quot;,
        &quot;1922&quot;,
        &quot;1923&quot;,
        &quot;A&quot;,
    ],
]

n_questions = len(all_questions_info)

clicked = False


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        global clicked

        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_index = 0

        while question_index &lt; n_questions:

            question_info = all_questions_info[question_index]

            question = question_info[0]
            ans_A = &quot;A: &quot; + question_info[1]
            ans_B = &quot;B: &quot; + question_info[2]
            ans_C = &quot;C: &quot; + question_info[3]

            text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
            self.say(text)

            clicked = False
            while not clicked:
                pass

            question_index += 1


class AnswerA(pytch.Sprite):
    Costumes = [&quot;button-ans-A.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(-140, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked
        clicked = True


class AnswerB(pytch.Sprite):
    Costumes = [&quot;button-ans-B.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(0, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked
        clicked = True


class AnswerC(pytch.Sprite):
    Costumes = [&quot;button-ans-C.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(140, -120)
" data-slug="add-AnswerB-clicked-handler"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>80</pre></td><td class="linenum"><pre>80</pre></td><td><pre>    def setup(self):</pre></td></tr><tr><td class="linenum"><pre>81</pre></td><td class="linenum"><pre>81</pre></td><td><pre>        self.go_to_xy(0, -120)</pre></td></tr><tr><td class="linenum"><pre>82</pre></td><td class="linenum"><pre>82</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-add" data-added-text="    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked
        clicked = True

"><tr><td class="linenum"></td><td class="linenum"><pre>83</pre></td><td><pre>    @pytch.when_this_sprite_clicked</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>84</pre></td><td><pre>    def notify_answered(self):</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>85</pre></td><td><pre>        global clicked</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>86</pre></td><td><pre>        clicked = True</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>87</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>83</pre></td><td class="linenum"><pre>88</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>84</pre></td><td class="linenum"><pre>89</pre></td><td><pre>class AnswerC(pytch.Sprite):</pre></td></tr><tr><td class="linenum"><pre>85</pre></td><td class="linenum"><pre>90</pre></td><td><pre>    Costumes = ["button-ans-C.png"]</pre></td></tr></tbody></table></div></div><p>And for <code>AnswerC</code>:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
    [
        &quot;What year was the Anglo-Irish Treaty signed?&quot;,
        &quot;1921&quot;,
        &quot;1922&quot;,
        &quot;1923&quot;,
        &quot;A&quot;,
    ],
]

n_questions = len(all_questions_info)

clicked = False


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        global clicked

        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_index = 0

        while question_index &lt; n_questions:

            question_info = all_questions_info[question_index]

            question = question_info[0]
            ans_A = &quot;A: &quot; + question_info[1]
            ans_B = &quot;B: &quot; + question_info[2]
            ans_C = &quot;C: &quot; + question_info[3]

            text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
            self.say(text)

            clicked = False
            while not clicked:
                pass

            question_index += 1


class AnswerA(pytch.Sprite):
    Costumes = [&quot;button-ans-A.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(-140, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked
        clicked = True


class AnswerB(pytch.Sprite):
    Costumes = [&quot;button-ans-B.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(0, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked
        clicked = True


class AnswerC(pytch.Sprite):
    Costumes = [&quot;button-ans-C.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(140, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked
        clicked = True
" data-slug="add-AnswerC-clicked-handler"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>92</pre></td><td class="linenum"><pre>92</pre></td><td><pre>    @pytch.when_green_flag_clicked</pre></td></tr><tr><td class="linenum"><pre>93</pre></td><td class="linenum"><pre>93</pre></td><td><pre>    def setup(self):</pre></td></tr><tr><td class="linenum"><pre>94</pre></td><td class="linenum"><pre>94</pre></td><td><pre>        self.go_to_xy(140, -120)</pre></td></tr></tbody><tbody class="diff-add" data-added-text="
    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked
        clicked = True
"><tr><td class="linenum"></td><td class="linenum"><pre>95</pre></td><td><pre></pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>96</pre></td><td><pre>    @pytch.when_this_sprite_clicked</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>97</pre></td><td><pre>    def notify_answered(self):</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>98</pre></td><td><pre>        global clicked</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>99</pre></td><td><pre>        clicked = True</pre></td></tr></tbody></table></div></div><p>Now you should be able to move onto the next question by clicking any
answer button.  Try it!</p><p>(Again, if you're wondering whether there's a better way to do all
this than copying and pasting code, you're right, but we don't have
space in this tutorial to discuss it.)</p></div><div class="chapter-content"><h2>Check the player's answer</h2><p>We're now very close to a working quiz game.  The narrator asks
questions, and the player can click on buttons to answer them.  But we
don't tell the player whether they got the questions right.</p><p>We need to know <em>which</em> answer button the player has clicked.  We'll
use another global variable for this information, so we'll define a
new variable near the top of the program:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
    [
        &quot;What year was the Anglo-Irish Treaty signed?&quot;,
        &quot;1921&quot;,
        &quot;1922&quot;,
        &quot;1923&quot;,
        &quot;A&quot;,
    ],
]

n_questions = len(all_questions_info)

clicked = False
answer = None


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        global clicked

        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_index = 0

        while question_index &lt; n_questions:

            question_info = all_questions_info[question_index]

            question = question_info[0]
            ans_A = &quot;A: &quot; + question_info[1]
            ans_B = &quot;B: &quot; + question_info[2]
            ans_C = &quot;C: &quot; + question_info[3]

            text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
            self.say(text)

            clicked = False
            while not clicked:
                pass

            question_index += 1


class AnswerA(pytch.Sprite):
    Costumes = [&quot;button-ans-A.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(-140, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked
        clicked = True


class AnswerB(pytch.Sprite):
    Costumes = [&quot;button-ans-B.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(0, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked
        clicked = True


class AnswerC(pytch.Sprite):
    Costumes = [&quot;button-ans-C.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(140, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked
        clicked = True
" data-slug="add-global-answer-variable"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>28</pre></td><td class="linenum"><pre>28</pre></td><td><pre>n_questions = len(all_questions_info)</pre></td></tr><tr><td class="linenum"><pre>29</pre></td><td class="linenum"><pre>29</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>30</pre></td><td class="linenum"><pre>30</pre></td><td><pre>clicked = False</pre></td></tr></tbody><tbody class="diff-add" data-added-text="answer = None
"><tr><td class="linenum"></td><td class="linenum"><pre>31</pre></td><td><pre>answer = None</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>31</pre></td><td class="linenum"><pre>32</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>32</pre></td><td class="linenum"><pre>33</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>33</pre></td><td class="linenum"><pre>34</pre></td><td><pre>class Narrator(pytch.Sprite):</pre></td></tr></tbody></table></div></div><p>The <code>None</code> value is a special Python value which means "nothing" or
"no value".  We have to assign <em>something</em> to a variable when
creating it.</p><p>Starting with the <code>AnswerA</code> sprite, within its
<code>when_this_sprite_clicked</code> code, we need to be able to use this
variable.  Add a declaration:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
    [
        &quot;What year was the Anglo-Irish Treaty signed?&quot;,
        &quot;1921&quot;,
        &quot;1922&quot;,
        &quot;1923&quot;,
        &quot;A&quot;,
    ],
]

n_questions = len(all_questions_info)

clicked = False
answer = None


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        global clicked

        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_index = 0

        while question_index &lt; n_questions:

            question_info = all_questions_info[question_index]

            question = question_info[0]
            ans_A = &quot;A: &quot; + question_info[1]
            ans_B = &quot;B: &quot; + question_info[2]
            ans_C = &quot;C: &quot; + question_info[3]

            text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
            self.say(text)

            clicked = False
            while not clicked:
                pass

            question_index += 1


class AnswerA(pytch.Sprite):
    Costumes = [&quot;button-ans-A.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(-140, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked, answer
        clicked = True


class AnswerB(pytch.Sprite):
    Costumes = [&quot;button-ans-B.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(0, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked
        clicked = True


class AnswerC(pytch.Sprite):
    Costumes = [&quot;button-ans-C.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(140, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked
        clicked = True
" data-slug="add-global-answer-declaration-to-AnswerA"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>70</pre></td><td class="linenum"><pre>70</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>71</pre></td><td class="linenum"><pre>71</pre></td><td><pre>    @pytch.when_this_sprite_clicked</pre></td></tr><tr><td class="linenum"><pre>72</pre></td><td class="linenum"><pre>72</pre></td><td><pre>    def notify_answered(self):</pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>73</pre></td><td class="linenum"></td><td><pre>        global clicked</pre></td></tr></tbody><tbody class="diff-add" data-added-text="        global clicked, answer
"><tr><td class="linenum"></td><td class="linenum"><pre>73</pre></td><td><pre>        global clicked, answer</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>74</pre></td><td class="linenum"><pre>74</pre></td><td><pre>        clicked = True</pre></td></tr><tr><td class="linenum"><pre>75</pre></td><td class="linenum"><pre>75</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>76</pre></td><td class="linenum"><pre>76</pre></td><td><pre></pre></td></tr></tbody></table></div></div><p>And add code to set the <code>answer</code> variable to the answer chosen by the
player if they click <code>AnswerA</code>:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
    [
        &quot;What year was the Anglo-Irish Treaty signed?&quot;,
        &quot;1921&quot;,
        &quot;1922&quot;,
        &quot;1923&quot;,
        &quot;A&quot;,
    ],
]

n_questions = len(all_questions_info)

clicked = False
answer = None


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        global clicked

        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_index = 0

        while question_index &lt; n_questions:

            question_info = all_questions_info[question_index]

            question = question_info[0]
            ans_A = &quot;A: &quot; + question_info[1]
            ans_B = &quot;B: &quot; + question_info[2]
            ans_C = &quot;C: &quot; + question_info[3]

            text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
            self.say(text)

            clicked = False
            while not clicked:
                pass

            question_index += 1


class AnswerA(pytch.Sprite):
    Costumes = [&quot;button-ans-A.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(-140, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked, answer
        answer = &quot;A&quot;
        clicked = True


class AnswerB(pytch.Sprite):
    Costumes = [&quot;button-ans-B.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(0, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked
        clicked = True


class AnswerC(pytch.Sprite):
    Costumes = [&quot;button-ans-C.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(140, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked
        clicked = True
" data-slug="assign-answer-var-in-AnswerA"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>71</pre></td><td class="linenum"><pre>71</pre></td><td><pre>    @pytch.when_this_sprite_clicked</pre></td></tr><tr><td class="linenum"><pre>72</pre></td><td class="linenum"><pre>72</pre></td><td><pre>    def notify_answered(self):</pre></td></tr><tr><td class="linenum"><pre>73</pre></td><td class="linenum"><pre>73</pre></td><td><pre>        global clicked, answer</pre></td></tr></tbody><tbody class="diff-add" data-added-text='        answer = "A"
'><tr><td class="linenum"></td><td class="linenum"><pre>74</pre></td><td><pre>        answer = "A"</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>74</pre></td><td class="linenum"><pre>75</pre></td><td><pre>        clicked = True</pre></td></tr><tr><td class="linenum"><pre>75</pre></td><td class="linenum"><pre>76</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>76</pre></td><td class="linenum"><pre>77</pre></td><td><pre></pre></td></tr></tbody></table></div></div><p>We can do something very similar for <code>AnswerB</code>:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
    [
        &quot;What year was the Anglo-Irish Treaty signed?&quot;,
        &quot;1921&quot;,
        &quot;1922&quot;,
        &quot;1923&quot;,
        &quot;A&quot;,
    ],
]

n_questions = len(all_questions_info)

clicked = False
answer = None


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        global clicked

        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_index = 0

        while question_index &lt; n_questions:

            question_info = all_questions_info[question_index]

            question = question_info[0]
            ans_A = &quot;A: &quot; + question_info[1]
            ans_B = &quot;B: &quot; + question_info[2]
            ans_C = &quot;C: &quot; + question_info[3]

            text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
            self.say(text)

            clicked = False
            while not clicked:
                pass

            question_index += 1


class AnswerA(pytch.Sprite):
    Costumes = [&quot;button-ans-A.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(-140, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked, answer
        answer = &quot;A&quot;
        clicked = True


class AnswerB(pytch.Sprite):
    Costumes = [&quot;button-ans-B.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(0, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked, answer
        answer = &quot;B&quot;
        clicked = True


class AnswerC(pytch.Sprite):
    Costumes = [&quot;button-ans-C.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(140, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked
        clicked = True
" data-slug="assign-answer-var-in-AnswerB"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>84</pre></td><td class="linenum"><pre>84</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>85</pre></td><td class="linenum"><pre>85</pre></td><td><pre>    @pytch.when_this_sprite_clicked</pre></td></tr><tr><td class="linenum"><pre>86</pre></td><td class="linenum"><pre>86</pre></td><td><pre>    def notify_answered(self):</pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>87</pre></td><td class="linenum"></td><td><pre>        global clicked</pre></td></tr></tbody><tbody class="diff-add" data-added-text='        global clicked, answer
        answer = "B"
'><tr><td class="linenum"></td><td class="linenum"><pre>87</pre></td><td><pre>        global clicked, answer</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>88</pre></td><td><pre>        answer = "B"</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>88</pre></td><td class="linenum"><pre>89</pre></td><td><pre>        clicked = True</pre></td></tr><tr><td class="linenum"><pre>89</pre></td><td class="linenum"><pre>90</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>90</pre></td><td class="linenum"><pre>91</pre></td><td><pre></pre></td></tr></tbody></table></div></div><p>And for <code>AnswerC</code>:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
    [
        &quot;What year was the Anglo-Irish Treaty signed?&quot;,
        &quot;1921&quot;,
        &quot;1922&quot;,
        &quot;1923&quot;,
        &quot;A&quot;,
    ],
]

n_questions = len(all_questions_info)

clicked = False
answer = None


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        global clicked

        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_index = 0

        while question_index &lt; n_questions:

            question_info = all_questions_info[question_index]

            question = question_info[0]
            ans_A = &quot;A: &quot; + question_info[1]
            ans_B = &quot;B: &quot; + question_info[2]
            ans_C = &quot;C: &quot; + question_info[3]

            text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
            self.say(text)

            clicked = False
            while not clicked:
                pass

            question_index += 1


class AnswerA(pytch.Sprite):
    Costumes = [&quot;button-ans-A.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(-140, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked, answer
        answer = &quot;A&quot;
        clicked = True


class AnswerB(pytch.Sprite):
    Costumes = [&quot;button-ans-B.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(0, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked, answer
        answer = &quot;B&quot;
        clicked = True


class AnswerC(pytch.Sprite):
    Costumes = [&quot;button-ans-C.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(140, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked, answer
        answer = &quot;C&quot;
        clicked = True
" data-slug="assign-answer-var-in-AnswerC"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>98</pre></td><td class="linenum"><pre>98</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>99</pre></td><td class="linenum"><pre>99</pre></td><td><pre>    @pytch.when_this_sprite_clicked</pre></td></tr><tr><td class="linenum"><pre>100</pre></td><td class="linenum"><pre>100</pre></td><td><pre>    def notify_answered(self):</pre></td></tr></tbody><tbody class="diff-del"><tr><td class="linenum"><pre>101</pre></td><td class="linenum"></td><td><pre>        global clicked</pre></td></tr></tbody><tbody class="diff-add" data-added-text='        global clicked, answer
        answer = "C"
'><tr><td class="linenum"></td><td class="linenum"><pre>101</pre></td><td><pre>        global clicked, answer</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>102</pre></td><td><pre>        answer = "C"</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>102</pre></td><td class="linenum"><pre>103</pre></td><td><pre>        clicked = True</pre></td></tr></tbody></table></div></div><p>Back in the narrator, once the <code>clicked</code> variable has turned <code>True</code>,
we can use the <code>[4]</code> item in our <code>question_info</code> list to know what the
correct answer is:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
    [
        &quot;What year was the Anglo-Irish Treaty signed?&quot;,
        &quot;1921&quot;,
        &quot;1922&quot;,
        &quot;1923&quot;,
        &quot;A&quot;,
    ],
]

n_questions = len(all_questions_info)

clicked = False
answer = None


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        global clicked

        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_index = 0

        while question_index &lt; n_questions:

            question_info = all_questions_info[question_index]

            question = question_info[0]
            ans_A = &quot;A: &quot; + question_info[1]
            ans_B = &quot;B: &quot; + question_info[2]
            ans_C = &quot;C: &quot; + question_info[3]

            text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
            self.say(text)

            clicked = False
            while not clicked:
                pass

            correct_answer = question_info[4]

            question_index += 1


class AnswerA(pytch.Sprite):
    Costumes = [&quot;button-ans-A.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(-140, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked, answer
        answer = &quot;A&quot;
        clicked = True


class AnswerB(pytch.Sprite):
    Costumes = [&quot;button-ans-B.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(0, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked, answer
        answer = &quot;B&quot;
        clicked = True


class AnswerC(pytch.Sprite):
    Costumes = [&quot;button-ans-C.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(140, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked, answer
        answer = &quot;C&quot;
        clicked = True
" data-slug="define-correct-answer-variable"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>58</pre></td><td class="linenum"><pre>58</pre></td><td><pre>            while not clicked:</pre></td></tr><tr><td class="linenum"><pre>59</pre></td><td class="linenum"><pre>59</pre></td><td><pre>                pass</pre></td></tr><tr><td class="linenum"><pre>60</pre></td><td class="linenum"><pre>60</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-add" data-added-text="            correct_answer = question_info[4]

"><tr><td class="linenum"></td><td class="linenum"><pre>61</pre></td><td><pre>            correct_answer = question_info[4]</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>62</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>61</pre></td><td class="linenum"><pre>63</pre></td><td><pre>            question_index += 1</pre></td></tr><tr><td class="linenum"><pre>62</pre></td><td class="linenum"><pre>64</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>63</pre></td><td class="linenum"><pre>65</pre></td><td><pre></pre></td></tr></tbody></table></div></div><p>And now we can use an <code>if</code>/<code>else</code> statement to say something different
depending on whether the player's answer is correct.  Notice that <code>==</code>
(two equals signs) is how you ask "are these two things equal?".  It's
easy to confuse this with <code>=</code> (just one equals sign), which means "set
a variable".</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
    [
        &quot;What year was the Anglo-Irish Treaty signed?&quot;,
        &quot;1921&quot;,
        &quot;1922&quot;,
        &quot;1923&quot;,
        &quot;A&quot;,
    ],
]

n_questions = len(all_questions_info)

clicked = False
answer = None


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        global clicked

        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        question_index = 0

        while question_index &lt; n_questions:

            question_info = all_questions_info[question_index]

            question = question_info[0]
            ans_A = &quot;A: &quot; + question_info[1]
            ans_B = &quot;B: &quot; + question_info[2]
            ans_C = &quot;C: &quot; + question_info[3]

            text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
            self.say(text)

            clicked = False
            while not clicked:
                pass

            correct_answer = question_info[4]
            if answer == correct_answer:
                self.say_for_seconds(&quot;Correct!&quot;, 2)
            else:
                self.say_for_seconds(&quot;Sorry, that's not correct.&quot;, 2)

            question_index += 1


class AnswerA(pytch.Sprite):
    Costumes = [&quot;button-ans-A.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(-140, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked, answer
        answer = &quot;A&quot;
        clicked = True


class AnswerB(pytch.Sprite):
    Costumes = [&quot;button-ans-B.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(0, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked, answer
        answer = &quot;B&quot;
        clicked = True


class AnswerC(pytch.Sprite):
    Costumes = [&quot;button-ans-C.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(140, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked, answer
        answer = &quot;C&quot;
        clicked = True
" data-slug="tell-user-whether-answer-correct"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>59</pre></td><td class="linenum"><pre>59</pre></td><td><pre>                pass</pre></td></tr><tr><td class="linenum"><pre>60</pre></td><td class="linenum"><pre>60</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>61</pre></td><td class="linenum"><pre>61</pre></td><td><pre>            correct_answer = question_info[4]</pre></td></tr></tbody><tbody class="diff-add" data-added-text="            if answer == correct_answer:
                self.say_for_seconds(&quot;Correct!&quot;, 2)
            else:
                self.say_for_seconds(&quot;Sorry, that's not correct.&quot;, 2)
"><tr><td class="linenum"></td><td class="linenum"><pre>62</pre></td><td><pre>            if answer == correct_answer:</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>63</pre></td><td><pre>                self.say_for_seconds("Correct!", 2)</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>64</pre></td><td><pre>            else:</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>65</pre></td><td><pre>                self.say_for_seconds("Sorry, that's not correct.", 2)</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>62</pre></td><td class="linenum"><pre>66</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>63</pre></td><td class="linenum"><pre>67</pre></td><td><pre>            question_index += 1</pre></td></tr><tr><td class="linenum"><pre>64</pre></td><td class="linenum"><pre>68</pre></td><td><pre></pre></td></tr></tbody></table></div></div><p>Try your quiz now — the narrator should tell you whether you got each
question right or wrong.</p></div><div class="chapter-content"><h2>Keep track of the player's score</h2><p>A nice feature would be to tell the player how many questions they got
right.</p><p>We'll keep track of the player's score as they answer the questions
one at a time.  Only the narrator needs to know the score, so we'll
use a <em>local</em> variable for this.  At the start of the quiz, the player
has no points, so we'll start <code>score</code> off at zero:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
    [
        &quot;What year was the Anglo-Irish Treaty signed?&quot;,
        &quot;1921&quot;,
        &quot;1922&quot;,
        &quot;1923&quot;,
        &quot;A&quot;,
    ],
]

n_questions = len(all_questions_info)

clicked = False
answer = None


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        global clicked

        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        score = 0
        question_index = 0

        while question_index &lt; n_questions:

            question_info = all_questions_info[question_index]

            question = question_info[0]
            ans_A = &quot;A: &quot; + question_info[1]
            ans_B = &quot;B: &quot; + question_info[2]
            ans_C = &quot;C: &quot; + question_info[3]

            text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
            self.say(text)

            clicked = False
            while not clicked:
                pass

            correct_answer = question_info[4]
            if answer == correct_answer:
                self.say_for_seconds(&quot;Correct!&quot;, 2)
            else:
                self.say_for_seconds(&quot;Sorry, that's not correct.&quot;, 2)

            question_index += 1


class AnswerA(pytch.Sprite):
    Costumes = [&quot;button-ans-A.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(-140, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked, answer
        answer = &quot;A&quot;
        clicked = True


class AnswerB(pytch.Sprite):
    Costumes = [&quot;button-ans-B.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(0, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked, answer
        answer = &quot;B&quot;
        clicked = True


class AnswerC(pytch.Sprite):
    Costumes = [&quot;button-ans-C.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(140, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked, answer
        answer = &quot;C&quot;
        clicked = True
" data-slug="initialise-local-score-variable"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>40</pre></td><td class="linenum"><pre>40</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>41</pre></td><td class="linenum"><pre>41</pre></td><td><pre>        self.say_for_seconds("Let's begin!", 3)</pre></td></tr><tr><td class="linenum"><pre>42</pre></td><td class="linenum"><pre>42</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-add" data-added-text="        score = 0
"><tr><td class="linenum"></td><td class="linenum"><pre>43</pre></td><td><pre>        score = 0</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>43</pre></td><td class="linenum"><pre>44</pre></td><td><pre>        question_index = 0</pre></td></tr><tr><td class="linenum"><pre>44</pre></td><td class="linenum"><pre>45</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>45</pre></td><td class="linenum"><pre>46</pre></td><td><pre>        while question_index &lt; n_questions:</pre></td></tr></tbody></table></div></div><p>If the player gets a question right, they get a point.  We already
have the <code>if</code>/<code>else</code> code which tells the player whether they got the
question right, so we can add some code here:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
    [
        &quot;What year was the Anglo-Irish Treaty signed?&quot;,
        &quot;1921&quot;,
        &quot;1922&quot;,
        &quot;1923&quot;,
        &quot;A&quot;,
    ],
]

n_questions = len(all_questions_info)

clicked = False
answer = None


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        global clicked

        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        score = 0
        question_index = 0

        while question_index &lt; n_questions:

            question_info = all_questions_info[question_index]

            question = question_info[0]
            ans_A = &quot;A: &quot; + question_info[1]
            ans_B = &quot;B: &quot; + question_info[2]
            ans_C = &quot;C: &quot; + question_info[3]

            text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
            self.say(text)

            clicked = False
            while not clicked:
                pass

            correct_answer = question_info[4]
            if answer == correct_answer:
                self.say_for_seconds(&quot;Correct!&quot;, 2)
                score += 1
            else:
                self.say_for_seconds(&quot;Sorry, that's not correct.&quot;, 2)

            question_index += 1


class AnswerA(pytch.Sprite):
    Costumes = [&quot;button-ans-A.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(-140, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked, answer
        answer = &quot;A&quot;
        clicked = True


class AnswerB(pytch.Sprite):
    Costumes = [&quot;button-ans-B.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(0, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked, answer
        answer = &quot;B&quot;
        clicked = True


class AnswerC(pytch.Sprite):
    Costumes = [&quot;button-ans-C.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(140, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked, answer
        answer = &quot;C&quot;
        clicked = True
" data-slug="award-point-for-correct-answer"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>62</pre></td><td class="linenum"><pre>62</pre></td><td><pre>            correct_answer = question_info[4]</pre></td></tr><tr><td class="linenum"><pre>63</pre></td><td class="linenum"><pre>63</pre></td><td><pre>            if answer == correct_answer:</pre></td></tr><tr><td class="linenum"><pre>64</pre></td><td class="linenum"><pre>64</pre></td><td><pre>                self.say_for_seconds("Correct!", 2)</pre></td></tr></tbody><tbody class="diff-add" data-added-text="                score += 1
"><tr><td class="linenum"></td><td class="linenum"><pre>65</pre></td><td><pre>                score += 1</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>65</pre></td><td class="linenum"><pre>66</pre></td><td><pre>            else:</pre></td></tr><tr><td class="linenum"><pre>66</pre></td><td class="linenum"><pre>67</pre></td><td><pre>                self.say_for_seconds("Sorry, that's not correct.", 2)</pre></td></tr><tr><td class="linenum"><pre>67</pre></td><td class="linenum"><pre>68</pre></td><td><pre></pre></td></tr></tbody></table></div></div><p>After asking all the questions, we want the narrator to announce the
score.  First we'll put together the text of what the narrator will
say.  We have already seen how to glue strings together to make one
big string by using the <code>+</code> operator.  But this time it's more
complicated, because the pieces we want to join together are:</p><ul>
<li>the string <code>"You got"</code>;</li>
<li>the number of questions the player got right — this is the value of
  the variable <code>score</code>;</li>
<li>the string <code>"out of"</code>;</li>
<li>the total number of questions — this is the value of the variable
  <code>n_questions</code>.</li>
</ul><p>But we can't just do</p><pre><code class="language-python">"You got" + score + "out of" + n_questions
</code></pre><p>because <code>score</code> refers to a <em>number</em> not a <em>string</em>.  Before we can
use <code>+</code> to join <code>"You got"</code> to the score, we have to convert the value
of <code>score</code> into a string.  Python has a built-in function <code>str()</code> for
this.</p><p>Another detail is that we need to include the space between <code>"You
got"</code> and the score, and the spaces around <code>"out of"</code>.</p><p>Putting this all together, we want to compute</p><pre><code class="language-python">"You got " + str(score) + " out of " + str(n_questions)
</code></pre><p>We'll store the result in the variable <code>text</code>.  Be very careful of the
indentation of the next line of code — it needs to be level with the
<code>while</code> at the top of the loop, so that the new code is <em>outside</em> the
<code>while</code> loop.</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
    [
        &quot;What year was the Anglo-Irish Treaty signed?&quot;,
        &quot;1921&quot;,
        &quot;1922&quot;,
        &quot;1923&quot;,
        &quot;A&quot;,
    ],
]

n_questions = len(all_questions_info)

clicked = False
answer = None


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        global clicked

        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        score = 0
        question_index = 0

        while question_index &lt; n_questions:

            question_info = all_questions_info[question_index]

            question = question_info[0]
            ans_A = &quot;A: &quot; + question_info[1]
            ans_B = &quot;B: &quot; + question_info[2]
            ans_C = &quot;C: &quot; + question_info[3]

            text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
            self.say(text)

            clicked = False
            while not clicked:
                pass

            correct_answer = question_info[4]
            if answer == correct_answer:
                self.say_for_seconds(&quot;Correct!&quot;, 2)
                score += 1
            else:
                self.say_for_seconds(&quot;Sorry, that's not correct.&quot;, 2)

            question_index += 1

        text = &quot;You got &quot; + str(score) + &quot; out of &quot; + str(n_questions)


class AnswerA(pytch.Sprite):
    Costumes = [&quot;button-ans-A.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(-140, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked, answer
        answer = &quot;A&quot;
        clicked = True


class AnswerB(pytch.Sprite):
    Costumes = [&quot;button-ans-B.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(0, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked, answer
        answer = &quot;B&quot;
        clicked = True


class AnswerC(pytch.Sprite):
    Costumes = [&quot;button-ans-C.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(140, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked, answer
        answer = &quot;C&quot;
        clicked = True
" data-slug="compute-final-score-text"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>68</pre></td><td class="linenum"><pre>68</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>69</pre></td><td class="linenum"><pre>69</pre></td><td><pre>            question_index += 1</pre></td></tr><tr><td class="linenum"><pre>70</pre></td><td class="linenum"><pre>70</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-add" data-added-text='        text = "You got " + str(score) + " out of " + str(n_questions)

'><tr><td class="linenum"></td><td class="linenum"><pre>71</pre></td><td><pre>        text = "You got " + str(score) + " out of " + str(n_questions)</pre></td></tr><tr><td class="linenum"></td><td class="linenum"><pre>72</pre></td><td><pre></pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>71</pre></td><td class="linenum"><pre>73</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>72</pre></td><td class="linenum"><pre>74</pre></td><td><pre>class AnswerA(pytch.Sprite):</pre></td></tr><tr><td class="linenum"><pre>73</pre></td><td class="linenum"><pre>75</pre></td><td><pre>    Costumes = ["button-ans-A.png"]</pre></td></tr></tbody></table></div></div><p>And then we can make the narrator make the announcement:</p><div class="patch-container" data-code-as-of-commit="import pytch


all_questions_info = [
    [
        &quot;What is the capital of Ireland?&quot;,
        &quot;Dublin&quot;,
        &quot;Cork&quot;,
        &quot;Galway&quot;,
        &quot;A&quot;,
    ],
    [
        &quot;How many centimetres are there in one metre?&quot;,
        &quot;10&quot;,
        &quot;100&quot;,
        &quot;1000&quot;,
        &quot;B&quot;,
    ],
    [
        &quot;What year was the Anglo-Irish Treaty signed?&quot;,
        &quot;1921&quot;,
        &quot;1922&quot;,
        &quot;1923&quot;,
        &quot;A&quot;,
    ],
]

n_questions = len(all_questions_info)

clicked = False
answer = None


class Narrator(pytch.Sprite):
    Costumes = [&quot;button-question.png&quot;]

    @pytch.when_green_flag_clicked
    def play_quiz(self):
        global clicked

        self.say_for_seconds(&quot;Let's begin!&quot;, 3)

        score = 0
        question_index = 0

        while question_index &lt; n_questions:

            question_info = all_questions_info[question_index]

            question = question_info[0]
            ans_A = &quot;A: &quot; + question_info[1]
            ans_B = &quot;B: &quot; + question_info[2]
            ans_C = &quot;C: &quot; + question_info[3]

            text = question + &quot;\n&quot; + ans_A + &quot;\n&quot; + ans_B + &quot;\n&quot; + ans_C
            self.say(text)

            clicked = False
            while not clicked:
                pass

            correct_answer = question_info[4]
            if answer == correct_answer:
                self.say_for_seconds(&quot;Correct!&quot;, 2)
                score += 1
            else:
                self.say_for_seconds(&quot;Sorry, that's not correct.&quot;, 2)

            question_index += 1

        text = &quot;You got &quot; + str(score) + &quot; out of &quot; + str(n_questions)
        self.say(text)


class AnswerA(pytch.Sprite):
    Costumes = [&quot;button-ans-A.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(-140, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked, answer
        answer = &quot;A&quot;
        clicked = True


class AnswerB(pytch.Sprite):
    Costumes = [&quot;button-ans-B.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(0, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked, answer
        answer = &quot;B&quot;
        clicked = True


class AnswerC(pytch.Sprite):
    Costumes = [&quot;button-ans-C.png&quot;]

    @pytch.when_green_flag_clicked
    def setup(self):
        self.go_to_xy(140, -120)

    @pytch.when_this_sprite_clicked
    def notify_answered(self):
        global clicked, answer
        answer = &quot;C&quot;
        clicked = True
" data-slug="announce-final-score"><div class="patch"><table><tbody class="diff-unch"><tr><td class="linenum"><pre>69</pre></td><td class="linenum"><pre>69</pre></td><td><pre>            question_index += 1</pre></td></tr><tr><td class="linenum"><pre>70</pre></td><td class="linenum"><pre>70</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>71</pre></td><td class="linenum"><pre>71</pre></td><td><pre>        text = "You got " + str(score) + " out of " + str(n_questions)</pre></td></tr></tbody><tbody class="diff-add" data-added-text="        self.say(text)
"><tr><td class="linenum"></td><td class="linenum"><pre>72</pre></td><td><pre>        self.say(text)</pre></td></tr></tbody><tbody class="diff-unch"><tr><td class="linenum"><pre>72</pre></td><td class="linenum"><pre>73</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>73</pre></td><td class="linenum"><pre>74</pre></td><td><pre></pre></td></tr><tr><td class="linenum"><pre>74</pre></td><td class="linenum"><pre>75</pre></td><td><pre>class AnswerA(pytch.Sprite):</pre></td></tr></tbody></table></div></div><p>Congratulations!  You should now have a working quiz game!</p></div><div class="chapter-content"><h2>Challenges</h2><p>Here are some ways you could improve the quiz:</p><ul>
<li>
<p>Add more questions.</p>
</li>
<li>
<p>Play a sound when the user gets an answer right, and a different
  sound if they get an answer wrong.  This tutorial comes with two
  sounds which might be useful for this, or you can use others.</p>
</li>
<li>
<p>Make narrator say the player's score so far, after each question has
  been answered.</p>
</li>
<li>
<p>(Harder:) Make there be <em>four</em> possible answers for each question.
  This tutorial comes with an image of a 'D' button you can use if you
  like.</p>
</li>
</ul></div><div class="chapter-content"><h2>Image and sound credits</h2><div class="asset-credits"><p class="credit-intro">For <code class="asset-filename">button-ans-A.png</code>, <code class="asset-filename">button-ans-B.png</code>, <code class="asset-filename">button-ans-C.png</code>, <code class="asset-filename">button-ans-D.png</code>, <code class="asset-filename">button-question.png</code> (used in the project):</p><div class="credits"><p>The button images are based on parts of a public-domain image located
on <a href="https://freesvg.org/5x3-glossy-buttons-vector-drawing">freesvg.org</a>.</p></div><p class="credit-intro">For <code class="asset-filename">short-cheer.mp3</code> (used in the project):</p><div class="credits"><p>The cheer sound effect is adapted from <a href="https://freesound.org/people/jayfrosting/sounds/333404/">an
original</a> by
freesound user <code>jayfrosting</code>, who kindly released it into the public
domain via the CC0 licence.</p></div><p class="credit-intro">For <code class="asset-filename">wrong-answer-buzz.mp3</code> (used in the project):</p><div class="credits"><p>The wrong answer buzzer sound effect is adapted from <a href="https://freesound.org/people/Glitchedtones/sounds/330366/">an
original</a>
by freesound user <code>Glitchedtones</code>, who kindly released it into the
public domain via the CC0 licence.</p></div><p class="credit-intro">For <code class="asset-filename">screenshot-w240.png</code> (used in the tutorial text/summary):</p><div class="credits"><p>The screenshot was created by the Pytch team, using project assets.</p></div></div></div></div>